home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.pascal
- Path: sparky!uunet!psgrain!qiclab!leonard
- From: leonard@qiclab.scn.rain.com (Leonard Erickson)
- Subject: Re: can't get EXEC to work
- Message-ID: <1992Sep1.032213.15901@qiclab.scn.rain.com>
- Keywords: EXEC
- Reply-To: 70465.203@compuserve.com
- Organization: SCN Research/Qic Laboratories of Tigard, Oregon.
- References: <la5469INNgd2@langtry.cs.utexas.edu>
- Date: Tue, 1 Sep 1992 03:22:13 GMT
- Lines: 36
-
- joel@cs.utexas.edu (Joel Daniel Just) writes:
-
- >I am having trouble getting the EXEC command to work in Turbo Pascal v5.0 on
- >the PC. Here is an example program:
-
- >PROGRAM TEST;
- >USES DOS;
- >BEGIN
- > EXEC('dir','');
- > WRITELN('DONE')
- >END.
-
- >When I run this program, 'DONE' is printed, and nothing else happens. The
- >EXEC command doesn't seem to be executed, no matter what I put in between the
- >two sets of quotes in the EXEC call. Even if I put garbage between the
- >quotes, I don't get an error. I just get 'DONE' and that's it.
-
- Well, the problem is that EXEC is *not* the same as BASIC's SHELL.
-
- It can only run EXE and COM files. "dir" is an internal command in
- COMMAND.COM. So you have to do an
- Exec(GetEnv('COMSPEC'),'/c dir');
- to get it to work. (The GetEnv is so that you get the *correct* command
- processor, as it may not be command.com and may not be on the path)
-
- Second, you *have* to use a $M directive at the start of the program
- or the heap will use all the free RAM and there won't be any left to
- run your Exec'ed program in!
-
- Always check the DosExitCode after an Exec. It'll let you know if it
- failed an if the program returned an errorlevel.
- --
- Leonard Erickson leonard@qiclab.scn.rain.com
- CIS: [70465,203] 70465.203@compuserve.com
- FIDO: 1:105/51 Leonard.Erickson@f51.n105.z1.fidonet.org
- (The CIS & Fido addresses are preferred)
-