execl()'ing batch files in DOS

Geoff Rimmer geoff at cs.warwick.ac.uk
Wed May 24 03:31:44 AEST 1989


In article <302 at ohs.UUCP> mday at ohs.UUCP (Matthew T. Day) writes:
> Does anybody know if it's possible to execl() a batch file in DOS?  I am
> using MicroSoft C v5.1, and using MS-DOS v3.30.  I have tried:
> 
> 	execl("\command.com", "tryit.bat", NULL);
> 
> and perror() tells me "No such file or directory."  Any help or input would
> be appreciated.

The \ character when in a string constant has a special meaning.  In
particular, it is used to produce special characters sucg as \n \t \r
\a \v etc.  To get a real \, you should double it: "\\command.com".
What you have written is actually undefined (according to ANSI C anyway).

BTW in QuickC (and also MSC5.1), you are often allowed to use the
UNIX-style '/' when calloing library functions such as "fopen".  Note
however that this will not work with the "system" function, and
probably not with the exec and spawn family of functions.

I was under the impression that to execute a batch file, you should
do:

	command.com -c batch.bat

In which case, you would require the following:

	execl("\\command.com", "\\command.com", "-c", "batch.bat", (char *)0);
		[a]		[b]		[c]	[d]		[e]

[a] says where the program is to be found.
[b] is argv[0] when command.com is run.
[c] is the command flag.
[d] is the batch file to run.
[e] is a pointer to char NULL.

Or maybe there's something about command.com that I don't know about?

> +------------------------------------------------+-------------------------+
> | UUCP: ...!uunet!iconsys!ohs!mday (Matthew Day) | "He who laughs, lasts." |
> | USMAIL: Orem H.S., 175 S 400 E, Orem, UT 84058 |                         |
> +------------------------------------------------+-------------------------+

	/---------------------------------------------------------------\
	|	GEOFF RIMMER						|
	|	email	: geoff at uk.ac.warwick.cs			|
	|	address : Computer Science Dept, Warwick University, 	|
	|		  Coventry, England.				|
	|	PHONE	: +44 203 692320				|
	|	FAX	: +44 865 726753				|
	\---------------------------------------------------------------/



More information about the Comp.lang.c mailing list