mday@ohs.UUCP (Matthew T. Day) (05/17/89)
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. -- +------------------------------------------------+-------------------------+ | UUCP: ...!uunet!iconsys!ohs!mday (Matthew Day) | "He who laughs, lasts." | | USMAIL: Orem H.S., 175 S 400 E, Orem, UT 84058 | | +------------------------------------------------+-------------------------+
rr5@prism.gatech.EDU (RAKES,RICHARD B) (05/17/89)
In article <302@ohs.UUCP> mday@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. >-- I am not a DOS user, I mostly program in a UNIX or MAC environment, but I can make a logical guess as to your problem. Remember that C strings use the backslash '\' character as an 'escape' character. In your example, the '\c' is probably being interpreted as simply the ASCII letter 'c' since I don't think there is a a MSC interpretation for that sequence. Anyway, what you probably need to do is use two backslashes so that the second one would be taken literally as in: execl("\\command.com", "tryit.bat", NULL); Also, my understanding is that MSC understands the RIGHT way :-) to delimit directories in a pathname and will handle 'forward slashes.' Thus, an alternative would be: execl("/command.com", "tryit.bat", NULL); -- RAKES,RICHARD B Georgia Institute of Technology, Atlanta Georgia, 30332 uucp: ...!{allegra,amd,hplabs,ut-ngp}!gatech!prism!rr5 Internet: rr5@prism.gatech.edu
bph@buengc.BU.EDU (Blair P. Houghton) (05/18/89)
In article <302@ohs.UUCP> mday@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. Perhaps the backslash is causing the following c to be interpreted literally as a c, i.e., as though the backslash weren't there at all. I.e. it's actually doing the same as execl("command.com", "tryit.bat", NULL); which looks in the current dir, not in the root dir, for command.com. replace the single backslash with a double backslash, and the first will cause the second to be interpreted literally _by_the_compiler_... execl("\\command.com", "tryit.bat", NULL); now the string itself will contain the backslash. --Blair "Good thing it wasn't a trigraph. We might have stepped in it..."
mesmo@Portia.Stanford.EDU (Chris Johnson) (05/18/89)
In article <302@ohs.UUCP> mday@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. Sorry for posting this, I have trouble mailing to UUCP sites. There are at least two errors in the above line: 1) if you want to specify the root directory "\", you will have to use the escape sequence "\\" in the first argument to execl (re: K&R 1ed p.180) 2) you are using "tryit.bat" as the first argument to command.com; this doesn't do what you want it to Why not use: system("tryit.bat"); ?? This invokes command.com, and then attempts to locate & run your batch file. -- ============================================================================== Chris M Johnson === mesmo@portia.stanford.edu === "Grad school sucks rocks" "Imitation is the sincerest form of plagiarism" -- ALF ==============================================================================
dhesi@bsu-cs.bsu.edu (Rahul Dhesi) (05/18/89)
>> execl("\command.com", "tryit.bat", NULL); >> >>and perror() tells me "No such file or directory." char option[] = "/c"; char *comspec; if (msdos_version <= 3) option[0] = getswitchar(); /* Turbo C 2.0 */ else printf ("Please upgrade to UNIX\n"); if ((comspec = getenv("COMSPEC")) == NULL) comspec = "/command.com"; execl (comspec, comspec, option, "tryit.bat", (char *) NULL); perror ("execl"); I have not tested this. -- Rahul Dhesi <dhesi@bsu-cs.bsu.edu> UUCP: ...!{iuvax,pur-ee}!bsu-cs!dhesi
ked@garnet.berkeley.edu (Earl H. Kinmonth) (05/18/89)
>> >> execl("\command.com", "tryit.bat", NULL); >> There are a number of errors in this. The proper call to execl is execl(char *path, char *arg0, char *arg1, char *argN, NULL); Usually path = arg0 = executable program name. Second, command.com -c string is the pattern used to get command.com to execute something other than keyboard input. Assuming command.com is in the root directory of drive c:, try the command: path = "c:/command.com"; execl(path,path,"-c","tryit.bat",NULL); You should not need to use the backslash. If your version of execl is brain-dead and you must use a backslash, double it to get proper string interpretation. Earl H. Kinmonth History Department University of California, Davis Davis, California 95616 916-752-1636 (2300-0800 PDT for FAX) 916-752-0776 (secretary) ucbvax!ucdavis!ucdked!cck (email) cc-dnet.ucdavis.edu [128.120.2.251] (request ucdked, login as guest)
jb@CSUStan.EDU (John Birchfield) (05/18/89)
I have used spawnv () to execute bacth files from DOS in the following manner... char *Argv [] = { "command", "/C", "testbat", 0 }; spawnv (P_WAIT, "c:\\command.com", Argv); I'm not sure but I think that execl () would work more or less the same. - - === === John Birchfield 1575 Quail Ct. jb@koko.csustan.edu Turlock, CA 95380 (209) 634-6243
guy@auspex.auspex.com (Guy Harris) (05/18/89)
> execl("\command.com", "tryit.bat", NULL);
Oh, and as long as you're fixing this statement as per the other
comments, change "NULL" to "(char *)NULL". NULL may be defined, at
present, so as to make the code work without the cast, but the code
isn't correct without it; put the cast in anyway, so that:
1) you get into the habit of doing it, so that your code works
on systems where NULL *isn't* defined so as to make it work;
2) your code is protected against changes to the environment
that might make it no longer work.
(No, function prototypes won't fix this case, since "execl" needs a
prototype like:
int execl(char *, ...);
and the NULL matches the "...", so the compiler has no idea that an
actual argument of type "char *" is needed here.)
gorpong@telxon.uucp (Gordon C. Galligher) (05/19/89)
In article <302@ohs.UUCP> mday@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. Try: system("tryit.bat"); (Which will invoke whatever COMSPEC points to) Try: execl("\command.com", "command", "-c", "tryit.bat", NULL); This should work, but then you are forcing it to try to execute \command.com. You should look at either: 1). The 'SHELL' environment variable 2). The 'COMSPEC' environment variable One of these is bound to point to the try command processor which you should execute (but no guarantees.....:-) -- Gordon. Gordon C. Galligher <|> ...!uunet!telxon!gorpong <|> gorpong@teleng.uucp.uu.net Telxon Corporation <|> "Before they warped out of orbit I beamed the while kit Akron, Ohio, 44313 <|> and kabootle into their engine room." - Scotty (216) 867-3700 (3512)<|> (Trouble with Tribbles)
geoff@cs.warwick.ac.uk (Geoff Rimmer) (05/24/89)
In article <302@ohs.UUCP> mday@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@uk.ac.warwick.cs | | address : Computer Science Dept, Warwick University, | | Coventry, England. | | PHONE : +44 203 692320 | | FAX : +44 865 726753 | \---------------------------------------------------------------/
scm@datlog.co.uk ( Steve Mawer ) (05/24/89)
In article <2896@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes: >In article <302@ohs.UUCP> mday@ohs.UUCP (Matthew T. Day) writes: >> execl("\command.com", "tryit.bat", NULL); >> >replace the single backslash with a double backslash, and the first will >cause the second to be interpreted literally _by_the_compiler_... > > execl("\\command.com", "tryit.bat", NULL); > >now the string itself will contain the backslash. > Correct me if I'm wrong (as if you wouldn't :-) but the syntax for execl is: execl(pathname, arg0, arg1..., argn, NULL); so the first argument that command.com will see after its name is NULL. Shouldn't the statement say: execl("\\command.com", "command.com", "tryit.bat", NULL); It's some time since I used MSC on DOS (but I'm thankful for small mercies) and I haven't got the facilities (or the will) to check this out myself. Hope this helps. -- Steve C. Mawer <scm@datlog.co.uk> or < {backbone}!ukc!datlog!scm > Voice: +44 1 863 0383 (x2153)
t-davidw@microsoft.UUCP (David Weigant) (05/25/89)
>> execl("\command.com", "tryit.bat", NULL);
Com'on boys, let's remember the dual backslashes required inside string
literals.
dave...the syntax checker
ked@garnet.berkeley.edu (Earl H. Kinmonth) (05/25/89)
>Com'on boys, let's remember the dual backslashes required inside string >literals. It would also help to remember that you need "-c" or "/c" depending on your switch character in the call to command.com.
det@hawkmoon.MN.ORG (Derek E. Terveer) (05/26/89)
In article <2896@buengc.BU.EDU>, bph@buengc.BU.EDU (Blair P. Houghton) writes: > In article <302@ohs.UUCP> mday@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: I have had problems when exec()ing batch files. It always hung my pc. derek -- Derek Terveer det@hawkmoon.MN.ORG || ..!uunet!rosevax!elric!hawkmoon!det w(612)681-6986 h(612)688-0667 "A proper king is crowned" -- Thomas B. Costain
keck@nprdc.arpa (John Keck) (06/14/89)
In article <948@hawkmoon.MN.ORG> det@hawkmoon.MN.ORG (Derek E. Terveer) writes: >In article <2896@buengc.BU.EDU>, bph@buengc.BU.EDU (Blair P. Houghton) writes: >> In article <302@ohs.UUCP> mday@ohs.UUCP (Matthew T. Day) writes: >> >Does anybody know if it's possible to execl() a batch file in DOS? > >I have had problems when exec()ing batch files. It always hung my pc. > A batch file is a script which is interpreted by the shell. You exec the shell specified by environment variable COMSPEC with the name of the file as an arg- ument. For COMMAND.COM, use the -C flag. All of this is done for you by the system() function.