• Please review our updated Terms and Rules here

MS-DOS TEMP variable

cr1901

Veteran Member
Joined
Dec 28, 2011
Messages
817
Location
NJ
Does anyone know when the TEMP variable was introduced into MS-DOS? Furthermore, does MS-DOS ever use the variable internally (like it does with the DIRCMD or PATH environment variable)?

The MS-DOS API appears to have a call to create a temporary file (int 21h, call 5ah), but I'm not certain if it uses TEMP, and it doesn't work for DOS 2.0 (one of my targets). Long story short, I'm trying to create a DOS-agnostic program (besides 1.0, which is worthless), but by design it needs to create a temporary file.

I could always just use getenv() in dos.h to get the value of TEMP, but I'm wondering if the DOS kernel provides services to automatically create the file in TEMP (feels more "proper"). Does anyone know what other programs did when they wanted to create a TEMP file?
 
Last edited:
Are you sure that MS-DOS ever used the TEMP variable? I thought it was only Windows somewhere along the line that started using that.
Anyway, it is easy to check: just boot up a standard MS-DOS floppy (in other words; no customizations) and try the command
Code:
echo %TEMP%
If you get a value, then MS-DOS sets it.
 
I don't think DOS itself uses the TEMP variable, but some of the third-party (Central Point, Norton) utilities that were included in DOS 6.x/PC DOS 7/2000 might use it.

It certainly doesn't hurt to define the TEMP variable to a directory of your choice (e.g. C:\TEMP), but if you're writing a DOS program, I wouldn't depend on it being pre-defined by the user.
 
Are you sure that MS-DOS ever used the TEMP variable? I thought it was only Windows somewhere along the line that started using that.
Anyway, it is easy to check: just boot up a standard MS-DOS floppy (in other words; no customizations) and try the command
Code:
echo %TEMP%
If you get a value, then MS-DOS sets it.

It's in my AUTOEXEC.BAT, but I don't remember setting it... at least for PC-DOS 5. My virtual install (the one I use for DOSBOX- i.e. Ran the install floppies within DOSBOX and installed MS-DOS 5 into a clean directory on my laptop) also has it set. Both these installs set TEMP=C:\DOS.
 
I'm not sure if dos created it or just some application did and folks checked if it existed upon installation and if not created it. As far as int21 function 5a here is helppc's definition (I often find they explain things nicer than many manuals). It seems to just create a random filename in the path you specify. You then have to delete the file when done as well, it's just mainly a temporary file name generator.
 
Correct--all 5A did was codify a procedure for naming a scratch file, instead of relying on an application to come up with something and risk stupid programmers from creating duplicates.

If you dig a little deeper, you'll find that not only TEMP gets used by some software, but that TMP also gets used. Usage, as usual is optional. If you want to find if a program uses TEMP, just set it to some non-existent drive location and start running your programs.

The naming of temporary files isn't really an issue unless you're multi-tasking.
 
I'm not sure if dos created it or just some application did and folks checked if it existed upon installation and if not created it.
I'll run a clean install of DOS and check later.


Correct--all 5A did was codify a procedure for naming a scratch file, instead of relying on an application to come up with something and risk stupid programmers from creating duplicates.

If you dig a little deeper, you'll find that not only TEMP gets used by some software, but that TMP also gets used. Usage, as usual is optional. If you want to find if a program uses TEMP, just set it to some non-existent drive location and start running your programs.

The naming of temporary files isn't really an issue unless you're multi-tasking.

Stupid programmers? You mean like calling the file "TEMP.TXT" or something and expecting that no one came up with that (bad) naming convention previously?

I guess I should make the variable optional then too, set it to a default value if it's not found, and write it to AUTOEXEC.BAT. As for multitasking- it might be worth the trouble for this application to give two "threads (in the loosest sense)", but only one thread would need to access the temp file, so no worries there.
 
Back
Top