PDA

View Full Version : Create a file in DOS??



Sebastiani
03-14-2004, 02:08 AM
I need to create a file from within a batch file, but I can't find a DOS command anywhere that does this. For now, I'm just redirecting a single character to the file (and thus creating it) - ugly hack, right?

Cheers.

Salem
03-14-2004, 02:22 AM
Just a guess

copy nul myfile

Sebastiani
03-14-2004, 03:00 AM
Nope (but nice try).

OK, ugly hack #2:

type nul > myfile

...dos sucks. :)

VirtualAce
03-14-2004, 02:54 PM
Look up DOS interrupt 21h in Ralph Brown's Interrupt List.

Sebastiani
03-14-2004, 04:44 PM
You can call an interrupt from a batch file?

Hammer
03-14-2004, 08:03 PM
>>I need to create a file from within a batch file
And you can't write a program to do that for you (create the file)?

>>copy nul myfile
... as expected, this works for me. What errors do you get?

>>type nul > myfile
... would've been my second choice after copy.

VirtualAce
03-15-2004, 12:39 AM
Well no, but creating a file from within a batch file does not fall under DOS programming. That falls more under what can be done in DOS from a user viewpoint rather than what can be accomplished in code under DOS.


edit <some_name>.bat



There are several batch commands for you to use inside of batch files. Look up DOS 6.22 batch commands on www.google.com and you will find all of em.

Sebastiani
03-15-2004, 03:08 AM
>> And you can't write a program to do that for you (create the file)?

I'm invoking a chain of compilation tools, the file in question gets created/destroyed somewhat dynamically.

>>copy nul myfile

All I get is '(0) Files copied' and no file.

Anyway, thanks for all of the suggestions. :)

VirtualAce
03-16-2004, 12:39 AM
Gimme more info Sebastiani and I can help. If anything I could code a simple program in C that could invoke DOS int 21h to do this for you.

Salem
03-16-2004, 02:17 AM
Well if you're going to the trouble of writing an external program, then a simple
fclose(fopen("file","w"));
type hack seems to be easy enough.

The 'touch' program on linux is a more capable version, and there are ports to the MS world.