Board index » delphi » Getting output of external application

Getting output of external application

Hi there,

In my application I would like to use an external application to do some
calculations. The reason for this is that it is a well tested piece of code
and it's written in C. Therfore I have no needs to translate it to delphi.
The application processes a file and shows progress on each line on screen.
To catch the output in DOS you can create a pipe for instance to a file. But
how do I do that in delphi?
Can I also create a pipe to the external application for the screen output?
And how about the input?? Is it also possible to create a pipe for input?

Many thanks, Darius Blaszijk

 

Re:Getting output of external application


Quote
Darius Blaszijk wrote in message ...
>Hi there,

>In my application I would like to use an external application to do some
>calculations. The reason for this is that it is a well tested piece of
code
>and it's written in C. Therfore I have no needs to translate it to delphi.
>The application processes a file and shows progress on each line on
screen.
>To catch the output in DOS you can create a pipe for instance to a file.
But
>how do I do that in delphi?
>Can I also create a pipe to the external application for the screen
output?
>And how about the input?? Is it also possible to create a pipe for input?

ISTR CreateProcess lets you supply generalised handles for standard
input, output and error. That means you can redirect them from and
to files, sockets and pipes. Unfortunately, pipes (which are what
you really want) are not supported in WfW (that includes WfW4.x=Win9x/ME),
only NT does them.

Groetjes,
Maarten Wiltink

Re:Getting output of external application


Quote
Darius Blaszijk wrote in message ...
>Hi there,

>In my application I would like to use an external application to do some
>calculations. The reason for this is that it is a well tested piece of
code
>and it's written in C. Therfore I have no needs to translate it to delphi.
>The application processes a file and shows progress on each line on
screen.
>To catch the output in DOS you can create a pipe for instance to a file.
But
>how do I do that in delphi?
>Can I also create a pipe to the external application for the screen
output?
>And how about the input?? Is it also possible to create a pipe for input?

ISTR CreateProcess lets you supply generalised handles for standard
input, output and error. That means you can redirect them from and
to files, sockets and pipes. Unfortunately, pipes (which are what
you really want) are not supported in WfW (that includes WfW4.x=Win9x/ME),
only NT does them.

Groetjes,
Maarten Wiltink

Re:Getting output of external application


On Sat, 27 Jan 2001 03:23:22 GMT, Andreas Kyriacou

Quote
<andrik...@zetnet.co.uk> wrote:
>The message <W9kc6.6055$iL1.110339@zonnet-reader-1>
>  from  "Darius Blaszijk" <DBlasz...@ZonNet.nl> contains these words:

>> Hi there,

>> In my application I would like to use an external application to do some
>> calculations. The reason for this is that it is a well tested piece of code
>> and it's written in C. Therfore I have no needs to translate it to delphi.
>> The application processes a file and shows progress on each line on screen.
>> To catch the output in DOS you can create a pipe for instance to a file. But
>> how do I do that in delphi?
>> Can I also create a pipe to the external application for the screen output?
>> And how about the input?? Is it also possible to create a pipe for input?

Hi Darius,
Pipes are dangerous, they don't work in all versions of Windows. There
are references to this on the Ms site.
A different way of doing it is to use a console app.

var
 st : string;
 StartUpInfo : TStartupInfo;
 WinPlacement:TWindowPlacement;
begin
  //start a new console app and run xxxxx in it
  FillChar(StartupInfo,Sizeof(TStartupInfo),#0);
  StartupInfo.cb := Sizeof(TStartupInfo);
  AllocConsole;
  WinPlacement.Length:=sizeOf(TWindowPlacement);
  WinPlacement.showCmd:=sw_hide;
  SetWindowPlacement(GetForegroundWindow,@WinPlacement);
  st := ExtractFilePath(Application.ExeName)
                               +'xxxxx  command line';

CreateProcess(nil,PChar(st),nil,nil,FALSE,0,nil,nil,StartupInfo,ProcessInfo);
end;

then you can start a timer and on the timer event:

var CoordArray:TCoord;
      ReadBuffer:PChar;
      CharsRead:DWORD;
begin
  ReadBuffer:=StrAlloc(81);
  CoordArray.x:=0; CoordArray.y:=4;  // the line to read
  ReadConsoleOutputCharacter(GetStdHandle(Std_Output_Handle),
    Readbuffer,80,CoordArray,CharsRead);
//console app output line now in ReadBuffer
//check if console app done
  if WaitForSingleObject(ProcessInfo.hProcess,0)=WAIT_OBJECT_0 THEN
  begin
   Timer.Enabled:=FALSE;
   FreeConsole;
 end;
end;

for the input :
procedure SimulateKeystroke(Key : byte);
begin
  keybd_event(Key,0, 0, 0);
  keybd_event(Key,0, KEYEVENTF_KEYUP, 0);
end;

or

Delphi SuperPage (http://sunsite.icm.edu.pl/delphi/ )
sendkeys.zip (3,131 bytes) This is the component you've been waiting
for. Finally Delphi sends keys to any other application (works like
SendKeys in VB). FreeWare with Source. Works with Delphi 3 and 4. (
ver. 1.0, added 7-Jun-99, no src., This component was ONLY tested with
Delphi 3 and 4. ) by Pedro Gardete ( Pedro Gardete )

Other Threads