Board index » delphi » help about execute DOS command

help about execute DOS command

Dear all,
How to execute a DOS program with in a BGI enviroment?
I found diffcult to run EXEC command, since  {$M 8192,0,0}
is not allowed in BGI enviroment,
Please help me! thank you!
--
From Wong Hoi Ko,
auto...@hkstar.com,
Web master of TPCLC,
http://www.hkstar.com/~autokim,

 

Re:help about execute DOS command


 > since {$M 8192,0,0} is not allowd in BGI environment

It's not that its not allowed, it's that the BGI requires some heap space
to allocate drivers and whatnot. The above says "keep no extra memory for
heap space". Instead, try something like:

   {$m 16384,0,100000}

This gives you a 16K stack, and reserves roughly 100K for the programs own
heap, leaving the rest of memory available for shelled programs.

Cheers, Todd

Re:help about execute DOS command


In article <01bd6949$b4175900$4406a8c0@state09>,

Quote
Todd Fiske <tfi...@delphi.com> wrote:

>It's not that its not allowed, it's that the BGI requires some heap space
>to allocate drivers and whatnot. The above says "keep no extra memory for
>heap space". Instead, try something like:

>   {$m 16384,0,100000}

>This gives you a 16K stack, and reserves roughly 100K for the programs own
>heap, leaving the rest of memory available for shelled programs.

Or one could reduce the heap just for exec. In this way one does not
have to set any specific maximum heap at compile time. However, one must
make sure that there is enough free heap at the end of the heap.

Const execerror:boolean=false; { if set, exit ASAP }

procedure exec(const com,par:string);
var rg:registers;
Begin
  if execerror then begin     { If error is set, then just call dos.exec }
     dos.exec(com,par);       { in general one should exit without using }
     exit;                    { exec when execerror is set }
  End;
  rg.bx:=words(Heapptr).hi-prefixseg+1;
  rg.es:=prefixseg;
  rg.ah:=$4a;
  MsDos(rg);                  { Reduce the memory block }

  dos.exec(com,par);

  rg.bx:=words(HeapEnd).hi-prefixseg;
  rg.es:=prefixseg;
  rg.ah:=$4a;
  MsDos(rg);                  { Restore the memory block }
  if rg.flags and fcarry>0    { Could not reallocate? }
    then begin
           heapend:=heapptr;  { reduce the heap }
           execerror:=true;   { set the errorflag }
         End;
End;

The error flag is sext if one loads TSRs with exec(). The code works
only on TP 6.0+

Osmo

Other Threads