Are you meaning to change the COM Controls STDIN?, I didn't know they had
one...

Do you have any idea of how to do these things?, I really like the idea of a
pipe....

Please Please some code....

This is the routine I am using to shell out to the DOS program.

function TAdrockASPExecute.Execute: Integer;
var
    zAppName           : array[0..512] of char;
    zCurDir            : array[0..255] of char;
    fDefaultDirectoryZ : array[0..255] of char;
    zTitle             : array[0..255] of char;
    WorkDir            : String;
    StartupInfo        : TStartupInfo;
    ProcessInfo        : TProcessInformation;
  begin
    StrPCopy(zTitle,'Adrock');
    StrPCopy(zAppName,fFileSpec+' '+fCommandLineParameters);
    StrPCopy(fDefaultDirectoryZ, fDefaultDirectory);
    GetDir(0,WorkDir);
    StrPCopy(zCurDir,WorkDir);
    FillChar(StartupInfo,Sizeof(StartupInfo),#0);
    StartupInfo.cb := Sizeof(StartupInfo);
    StartupInfo.dwFlags :=  STARTF_USESHOWWINDOW;
    StartupInfo.wShowWindow := 1; { Show the window so I know it works }
    ScriptingContext.Response.Write('Filespec = ['+fFileSpec+'
'+fCommandLineParameters+']<P>');
    ScriptingContext.Response.Write('Default Directory =
['+fDefaultDirectory+']<P>');

    if not CreateProcess(
      nil,                           { Pointer to the Application Module to
execute }
      zAppName,                      { pointer to command line
       }
      nil,                           { pointer to process security
attributes       }
      nil,                           { pointer to thread security
tes        }
      false,                         { handle inheritance
     }
      CREATE_NEW_CONSOLE or          { creation
      }
      NORMAL_PRIORITY_CLASS,
      nil,                           { pointer to new environment
      }
      fDefaultDirectoryZ,            { pointer to current directory
     }
      StartupInfo,                   { pointer to
            }
      ProcessInfo) then
      Result := 0{ pointer to PROCESS_INF }
    else
     begin
       if (fWait <> 0) then
         begin
            { if the OnWaiting event has been set in code, then call the
event }
            HProcess := ProcessInfo.hProcess;
            WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
            GetExitCodeProcess(ProcessInfo.hProcess, fExitCode);
            { At this point the program we have just loaded has now just
finished }
         end;
       Result := 1;
     end
end;

Chris


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
Behalf Of Max Nilson
Sent: Tuesday, 5 October 1999 17:33
To: Multiple recipients of list Delphi
Subject: RE: [DUG]: Executing a simple program and capturing the output


> I have written a simple com component that shells out to a Command Line
> program.
>
> The program writes its output to the standard output device.
>
> What I want to do is capture this text output, does anyone know if it is
> possible?
>
> Do I have to redirect it to a file and then get read the file?

When you are doing the shelling you firstly set your standard in standard
error file handles to some useful file handle(s). This may be a file, a
pipe or what ever takes your fancy. The standard in should be pointed at
the nul device so that any reads on it will return EOF.

Once the program is spawned then you can go anout restoring all the
standard file handles back to their default values. You did save these
before by duping them didn't you? (8-)

Have a look fomr some standard Windows command line spawning components,
these should have examples of the gymnastics used to achieve this sort of
thing.

Cheers, Max.


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to