[comp.lang.pascal] Process handling/Memory and Ctrl-C

defaria@hpclapd.cup.hp.com (Andy DeFaria) (01/15/91)

Why do I get the following error messages?  The following program allocates
the smallest stack possible (1024) then Exec's SORT.  I  then hit Control-C
to abort the SORT operation and fail with the following two errors:

Runtime error 202 at 0010:09B9  { 202 = Stack overflow error }
Runtime error 105 at 0000:00D8  { 105 = File not open for output }

In a similar vein:  How can I release all  memory used  by   my program  to
whatever program I Exec and still be able to  reclaim  the memory back once
the Exec'ed program is finished?  I would like to allow any program  that I
start to have access to as much  memory as is  available to avoid potential
problems.

{$M 1024, 0, 0}
Program Foo;

Uses DOS;

Begin { Foo }
   WriteLn ('Executing C:\SYSTEM\DOS\SORT.EXE');
   
   Exec ('C:\SYSTEM\DOS\SORT.EXE');

   If DOSError <> 0 then
      WriteLn ('DOSError = ', DOSError : 1)
   else
      WriteLn ('Successful');

End. { Foo }

reino@cs.eur.nl (Reino de Boer) (01/16/91)

defaria@hpclapd.cup.hp.com (Andy DeFaria) writes:

>Why do I get the following error messages?  The following program allocates
>the smallest stack possible (1024) then Exec's SORT.  I  then hit Control-C
>to abort the SORT operation and fail with the following two errors:

>Runtime error 202 at 0010:09B9  { 202 = Stack overflow error }
>Runtime error 105 at 0000:00D8  { 105 = File not open for output }

>{$M 1024, 0, 0}
>Program Foo;

>Uses DOS;

>Begin { Foo }
>   WriteLn ('Executing C:\SYSTEM\DOS\SORT.EXE');
>   
>   Exec ('C:\SYSTEM\DOS\SORT.EXE');

My compiler warns me that I should have a second parameter. like:
    Exec ('C:\SYSTEM\DOS\SORT.EXE','');

>   If DOSError <> 0 then
>      WriteLn ('DOSError = ', DOSError : 1)
>   else
>      WriteLn ('Successful');

>End. { Foo }

But, more importantly, you need the following calling sequence:
    SwapVectors;
    Exec( ... );
    SwapVectors;
In which case all goes well (RTFM).

Reino
-- 
Reino R. A. de Boer     "We want to build the right product right, right?"
Erasmus University Rotterdam ( Informatica )
e-mail: reino@cs.eur.nl