Board index » delphi » Calling a Dos command\program from TP7.0

Calling a Dos command\program from TP7.0

Howdy, I'm pretty new to the TP thing and I was wondering if there's a way
to call commands/programs from a TP program.  I tried the EXEC procedure but
nothing ever happened for me.  I would Appreciate any help.
   ______              
  / __/ /____ _  _____   | stan...@upei.ca
 _\ \/ __/ -_) |/ / -_)  |       or
/___/\__/\__/|___/\__/   | stan...@isn.net
 

Re:Calling a Dos command\program from TP7.0


i am having the same problrm.  please e-mail me help.  i know i have to
say uses dos; at the top, but am confused about what arguments to send
exec.
jeb neal

Re:Calling a Dos command\program from TP7.0


Quote
> Howdy, I'm pretty new to the TP thing and I was wondering if there's a way
> to call commands/programs from a TP program.  I tried the EXEC procedure but
> nothing ever happened for me.  I would Appreciate any help.
>    ______              
>   / __/ /____ _  _____   | stan...@upei.ca
>  _\ \/ __/ -_) |/ / -_)  |       or
> /___/\__/\__/|___/\__/   | stan...@isn.net

I think you looking fore some thing like this:

{$M 8192,0,0}
{* This memory directive is used to make
   certain there is enough memory left
   to execute the DOS shell and any
   other programs needed.  *}

Program EXEC_Demo;

{*

  EXEC.PAS

  This program demonstrates the use of
  Pascal's EXEC function to execute
  either an individual DOS command or
  to move into a DOS Shell.

  You may enter any command you could
  normally enter at a DOS prompt and
  it will execute.  You may also hit
  RETURN without entering anything and
  you will enter into a DOS Shell, from
  which you can exit by typing EXIT.

  The program stops when you hit a
  'Q', upper or lower case.
*}

Uses Crt, Dos;

Var
  Command : String;

{**************************************}
Procedure Do_Exec; {*******************}

  Var
    Ch : Char;

  Begin
    If Command <> '' Then
      Command := '/C' + Command
    Else
      Writeln('Type EXIT to return from the DOS Shell.');
    {* The /C prefix is needed to
       execute any command other than
       the complete DOS Shell. *}

    SwapVectors;
    Exec(GetEnv('COMSPEC'), Command);
    {* GetEnv is used to read COMSPEC
       from the DOS environment so the
       program knows the correct path
       to COMMAND.COM. *}

    SwapVectors;
    Writeln;
    Writeln('DOS Error = ',DosError);
    If DosError <> 0 Then
      Writeln('Could not execute COMMAND.COM');
    {* We're assuming that the only
       reason DosError would be something
       other than 0 is if it couldn't
       find the COMMAND.COM, but there
       are other errors that can occur,
       we just haven't provided for them
       here. *}

    Writeln;
    Writeln;
    Writeln('Hit any key to continue...');
    Ch := ReadKey;
  End;

Function Get_Command : String;

  Var
    Count : Integer;
    Cmnd : String;

  Begin
    Clrscr;
    Write('Enter DOS Command (or Q to Quit): ');
    Readln(Cmnd);
    Get_Command := Cmnd
  End;

Begin
  Command := Get_Command;
  While NOT ((Command = 'Q') OR (Command = 'q')) Do
    Begin
      Do_Exec;
      Command := Get_Command
    End;
End.

Re:Calling a Dos command\program from TP7.0


Quote
>   thomas osterdahl <thomas.osterd...@mailbox.swipnet.se> writes:
>  > Howdy, I'm pretty new to the TP thing and I was wondering if there's a way
>  > to call commands/programs from a TP program.  I tried the EXEC procedure but
>  > nothing ever happened for me.  I would Appreciate any help.
>  >    ______              
>  >   / __/ /____ _  _____   | stan...@upei.ca
>  >  _\ \/ __/ -_) |/ / -_)  |       or
>  > /___/\__/\__/|___/\__/   | stan...@isn.net

>  I think you looking fore some thing like this:

One addidional caution:  check your memory settings.  Make sure the
upper limit of heap is not set to 640k ( or anything close to that).
I was doing a lot of exec'ing and getting nowhere, till I noted
(somewhere in the documentation, I think) that you must leave some
room on the heap for exec to work properly.

Cheers,
**********************************************************************
***  Cliff W. Estes                             ces...@seanet.com  ***
***  BaseLine Technology                         ph (206)882-7317  ***
***  15834 NE 67th Place                        fax (206)882-7327  ***
***  Redmond, WA  98052                                            ***
***   Home of BaseLine II, THE interactive hull fairing system     ***
**********************************************************************

Other Threads