[comp.lang.pascal] Dos Shell

kristgud@tharkas.is (Kristinn Gudnason) (03/26/91)

I'm writing a program and I need to be able to shell to dos from a unit.  
I'm not able to set the {$E xxxx,xxxx} feature.  I'm desperet for help!!!
    PLEASE  if you know how to do this, help me.

Thanks in advance.
        Kristinn Gudnason

dave@tygra.UUCP (David Conrad) (03/27/91)

In article <sTkDZ1w163w@tharkas.is> kristgud@tharkas.is (Kristinn Gudnason) writes:
>I'm writing a program and I need to be able to shell to dos from a unit.  
>I'm not able to set the {$E xxxx,xxxx} feature.  I'm desperet for help!!!

Place the {$M x,y,z} command in the main program file.  If the unit is to be
used by various client programs then it should specify in the documentation
that sufficient memory must be set aside or the shell will fail.  Test the
DosExitCode (q.v.) to see if it succeeded and don't forget to enclose the
Exec (q.v.) in a pair of SwapVectors (q.v.).

Dave Q. V. Conrad
dave%tygra@sharkey.cc.umich.edu
-- 
=  CAT-TALK Conferencing Network, Computer Conferencing and File Archive  =
-  1-313-343-0800, 300/1200/2400/9600 baud, 8/N/1. New users use 'new'    - 
=  as a login id.  AVAILABLE VIA PC-PURSUIT!!! (City code "MIDET")        =
   E-MAIL Address: dave%tygra@sharkey.cc.umich.edu

debotton@andromeda.rutgers.edu (Len DeBotton) (04/09/91)

   I am stuck.  I am doing a turbo pascal program in (versoin 4)
   that needs to exit to dos. Kind of like the OS shell in turbo
   pascal. Is there any way to do this. I tried to use the
   Exec procedure but did not have much luck. 
   
   Please respond to my account..Thanks
   


^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^ Leonard De Botton -- Dreams can come true^
^ debotton@andromeda.rutgers.edu           ^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

amead@s.psych.uiuc.edu (alan mead) (04/13/91)

debotton@andromeda.rutgers.edu (Len DeBotton) writes:


>   I am stuck.  I am doing a turbo pascal program in (versoin 4)
>   that needs to exit to dos. Kind of like the OS shell in turbo
>   pascal. Is there any way to do this. I tried to use the
>   Exec procedure but did not have much luck. 
>   
>   Please respond to my account..Thanks

Well, someone else just asked a similar question (wanted a TSR to log
activities).  I'm doing this from memory, but I believe:

SwapVectors;
Exec( 'C:\COMMAND.COM','' );
SwapVectors;

will do the trick.  In fact, if you don't want your code to bomb when
it runs on a platform that boots from D:, then use

Exec( GetEnv( 'COMSPEC' ),'' );

instead.  All this is in the manual under Exec() and GetEnv().  

What this does is "spawn a (DOS) shell" and the nifty thing is that DOS
will exit a (spawned) shell simply by typing 'exit'--in other words, your
OS Escape can be *exactly* like commercial programs, it's easy.  
Wordperfect takes this another step by changing the prompt to say
'Type EXIT to return to WordPerfect'#13#10.

NOTE that the implication of the above is that your spawned shell is left
with whatever RAM is not used.  Couple this with the fact that by default, 
your program nabs all RAM (for the heap) and you have trouble.  If you want
to shell out, you must minimize the stack and heap using the $M directive
(and remember that this directive has no effect in a unit, you have to do
it in the main module--you might want to use an (ugh) include file:

{$DEFINE HeapOK}
{$M xx,yy,zz }

and then test for it in your unit:

{$IFDEF HeapOK } 
SwapVectors;
Shellout;
SwapVectors;
{$ELSE }
PrintCannotShellOut;
{$ENDIF }

A really slick wizard could tell us how to swap to disk/EMS/XMS/...  At the
least, you need to use low-level DOS calls to release the memory (that 
hopefully isn't being used) for your shell and then claim it.  I've never 
known for sure whether TP does other things besides just requesting the
memory using DOS calls).

-alan mead : amead@s.psych.uiuc.edu