home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / pascal / 5142 < prev    next >
Encoding:
Text File  |  1992-08-31  |  1.8 KB  |  49 lines

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