[comp.lang.pascal] Question about Turbo Pascal's Exec

ugpolvin@cs.Buffalo.EDU (Joseph Polvino) (05/06/89)

I came across the Exec procedure, and it takes the form of:
   Exec(Path,CmdLine : string);
The way it looks to me is it will take a path like 'c:\' and a command
line like 'ted autoexec' and run ted on autoexec.

I have been unable to decypher how to use Exec, let along know if I'm 
using the correct procedure!  If anyone out there knows how to use Exec
or knows how to run a program within a TP procedure, I'd really appreciate
it.

Thanks for helping me (and others I'm sure) out!

---

Joe Polvino 
ugpolvin@cs.buffalo.edu
v058p7wh@ubvms.bitnet

leonard@bucket.UUCP (Leonard Erickson) (05/08/89)

In article <5708@cs.Buffalo.EDU> ugpolvin@cs.Buffalo.EDU (Joseph Polvino) writes:
<I came across the Exec procedure, and it takes the form of:
<   Exec(Path,CmdLine : string);
<The way it looks to me is it will take a path like 'c:\' and a command
<line like 'ted autoexec' and run ted on autoexec.

Check your manual again. What they want is something like this:
	Exec('c:\util\ne.com','autoexec.bat')

In other words, Path is the executable name *and* path. If the program
is on the DOS path, you can use just the name. The Cmdline is the
parameters to be passed.

To run a batch file do it like this:
	Exec('command.com','/c foo.bat')
if the bat file needs extra environment space, this may work (haven't
had a chance to try it yet...)
	Exec('command.com','/e:512 /c foo.bat')
-- 
Leonard Erickson		...!tektronix!reed!percival!bucket!leonard
CIS: [70465,203]
"I'm all in favor of keeping dangerous weapons out of the hands of fools.
Let's start with typewriters." -- Solomon Short

pcsuprt@pioneer.arc.nasa.gov (pcsuprt group) (05/09/89)

In reference to Exec(path, cmdline : string).

Path - this is the full path, name and extension of the program
that you want to execute.

Cmdline - this line will be passed to the executed program as a parm.

Thus to execute ted on autoexec.bat you would use:
Exec('c:\ted.com','c:\autoexec.bat');
(This assumes that ted.com is in the root on c:).

If ted is in the path and you don't wan't to specify exactly where it is
then use:  Exec('c:\command.com',' /c ted c:\autoexec.bat');
This loads the command interpreter and tells it to find ted and run it
(takes more memory and is slower).

When using the EXEC command be sure to pay attention to the memory.
Since the pascal program remains resident, you have that
much less memory to play with.  In particular, I have had to set the
stacksize to the maximum ( 65520 bytes ) in order to use
exec in a program I wrote.  I used the compiler directive {$M 65520,0,65536}.
Also, when testing the program compile it to disk instead of memory to
make more RAM available to Exec.

The DosError variable should be checked after running exec.  DosError will
tell you if you ran out of memory (8) or if the file could not be found (2),
etc.  DosExitCode is supposed to be the returncode from the program that exec
ran (although I haven't ever used it).
Dave Silvestro, Sterling Software, NASA/Ames Research Center
Moffett Field, CA       pcsuprt@pioneer.arc.nasa.gov

wagnere@gtephx.UUCP (Eric Wagner) (05/10/89)

In article <5708@cs.Buffalo.EDU>, ugpolvin@cs.Buffalo.EDU (Joseph Polvino) writes:
>    Exec(Path,CmdLine : string);

As I remember, the 'path' is the full pathname of the command
to execute, while the 'cmdline' is the list of parameters.

-- 
"...sitting there next to the insect electric
chair -- her skin gleaming blue every time a fly died..."
                                -- Was (Not Was)
    Eric Wagner    UUCP:  ...!ames!ncar!noao!asuvax!gtephx!wagnere

pilgrimk@lafcol.UUCP (Kenwyn A. Pilgrim) (05/10/89)

(pcsuprt group) writes:
# When using the EXEC command be sure to pay attention to the memory.
# Since the pascal program remains resident, you have that
# much less memory to play with.  In particular, I have had to set the
# stacksize to the maximum ( 65520 bytes ) in order to use
# exec in a program I wrote.  I used the compiler directive {$M 65520,0,65536}.
# Also, when testing the program compile it to disk instead of memory to
# make more RAM available to Exec.
# 
# Dave Silvestro, Sterling Software, NASA/Ames Research Center

I have used 

           {$M 2048,0,0}

successfully. What that means is that 2048 bytes is reserved for the stack
of the calling program.

You've got your facts WRONG! The compiler directives refer
to the amount of memory reserved for the CALLING program, NOT  the program
which is called by the Exec procedure. In the example above, no heap is
reserved, since the CALLING program used none of TP40's dynamic routines.

Try using the following and see what happens:

{$M $FFFF,0,655360} 

then invoke the command interpreter (command.com). If this is successful
(probably not, should get an error code of 8: not enough memory) 
then check to see how much mem is left.

Disclaimer: I'm didn't write the compiler so I may be wrong!

-Kenwyn (btw what is btw?)