Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uwm.edu!ux1.cso.uiuc.edu!s.psych.uiuc.edu!amead From: amead@s.psych.uiuc.edu (alan mead) Newsgroups: comp.lang.pascal Subject: Re: Dos Shell Message-ID: <1991Apr12.220723.26144@ux1.cso.uiuc.edu> Date: 12 Apr 91 22:07:23 GMT References: Sender: usenet@ux1.cso.uiuc.edu (News) Distribution: usa Organization: University of Illinois at Urbana Lines: 57 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