Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-10

Help for process

8 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

wile64

Hi all,

Je voudrais lancer un programme en ligne de commande (avec Tprocess ps de probl?me).

I would run an progam in command line (with Tprocess no problem).

1 - But with the recovery of messages for viewing in a TMemo. 2 - Do not block my application when read the data (the example of a wiki is awaiting data and read after)
3 - Send orders. (I think a TInput.write but it does not).

Is it possible ?

Thanks

Laurent. "If debugging is the art of removing bugs, then programming must be the art of creating!" My Components: http://wiki.lazarus.freepascal.org/Wile64 French Forum : http://lazforum-fr.tuxfamily.org/index.php -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20081008/bf0acb43/attachment.html

Reply by email

Vincent Snijders
to wile64
wile64 wrote 15 lines
Hi all, Je voudrais lancer un programme en ligne de commande (avec Tprocess ps de probl?me). I would run an progam in command line (with Tprocess no problem). 1 - But with the recovery of messages for viewing in a TMemo. 2 - Do not block my application when read the data (the example of a wiki is awaiting data and read after) 3 - Send orders. (I think a TInput.write but it does not). Is it possible ?

Yes, look at the last example in the wiki:
http://wiki.lazarus.freepascal.org/Executing_External_Programs#Using_input_and_output_of_a_TProcess

Vincent

Reply by email

wile64
to Vincent Snijders

2008/10/8 Vincent Snijders

Show quoted text 22 lines
wile64 schreef: > Hi all, > > Je voudrais lancer un programme en ligne de commande (avec Tprocess ps > de probl?me). > > I would run an progam in command line (with Tprocess no problem). > > 1 - But with the recovery of messages for viewing in a TMemo. > 2 - Do not block my application when read the data (the example of a > wiki is awaiting data and read after) > 3 - Send orders. (I think a TInput.write but it does not). > > Is it possible ? > > Yes, look at the last example in the wiki: http://wiki.lazarus.freepascal.org/Executing_External_Programs#Using_input_and_output_of_a_TProcess

Thanks Vincent,

This link dead this morning !

Laurent. "If debugging is the art of removing bugs, then programming must be the art of creating!" My Components: http://wiki.lazarus.freepascal.org/Wile64 French Forum : http://lazforum-fr.tuxfamily.org/index.php -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20081008/1dd3a1a0/attachment.html

Reply by email

wile64
to wile64

2008/10/8 wile64

Show quoted text 30 lines
2008/10/8 Vincent Snijders > wile64 schreef: > > Hi all, > > > > Je voudrais lancer un programme en ligne de commande (avec Tprocess ps > > de probl?me). > > > > I would run an progam in command line (with Tprocess no problem). > > > > 1 - But with the recovery of messages for viewing in a TMemo. > > 2 - Do not block my application when read the data (the example of a > > wiki is awaiting data and read after) > > 3 - Send orders. (I think a TInput.write but it does not). > > > > Is it possible ? > > > > > > Yes, look at the last example in the wiki: > > http://wiki.lazarus.freepascal.org/Executing_External_Programs#Using_input_and_output_of_a_TProcess > > Thanks Vincent, This link dead this morning !

This work, but not with the program launched :-(

It's posible an program (C++) not use stdin and stdout for create console ?

Thanks

Laurent. "If debugging is the art of removing bugs, then programming must be the art of creating!" My Components: http://wiki.lazarus.freepascal.org/Wile64 French Forum : http://lazforum-fr.tuxfamily.org/index.php -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20081008/e443ea78/attachment.html

Reply by email

Seth Grover
to wile64

At one point I used this function:

procedure ExecCommand(const command : string;
                            stdout : TStringList;
                            stderr : TStringList;
                      const timeoutSec : integer;
                      out   exitStatus : integer);
var
 P: TProcess;
 nOut : LongInt;
 nErr : LongInt;
 StdOutput : TMemoryStream;
 StdOutBytesRead: LongInt;
 StdError : TMemoryStream;
 StdErrBytesRead: LongInt;
 startTime : TDateTime;
begin
  exitStatus := -1;
  StdOutput := TMemoryStream.Create;
  StdError := TMemoryStream.Create;
  StdOutBytesRead := 0;
  StdErrBytesRead := 0;
  try
    P := TProcess.Create(nil);
    try
      P.CommandLine := command;
      P.Options := [poUsePipes];
      startTime := now;
      P.Execute;
      { read stderr and stdout while the process runs }
      while P.Running do begin
        StdOutput.SetSize(StdOutBytesRead + READ_BYTES);
        StdError.SetSize(StdErrBytesRead + READ_BYTES);
        nOut := P.Output.Read((StdOutput.Memory + StdOutBytesRead)^,
READ_BYTES);
        if nOut > 0 then begin
          Inc(StdOutBytesRead, nOut);
        end;
        nErr := P.Stderr.Read((StdError.Memory + StdErrBytesRead)^, READ_BYTES);
        if nErr > 0 then begin
          Inc(StdErrBytesRead, nErr);
        end;
        if (nErr = 0) and (nOut = 0) then Sleep(100);
        if (timeoutSec > 0) and (SecondsBetween(now, startTime) >
timeoutSec) then begin
          P.Terminate(exitStatus);
          raise Exception.Create('Execution timed out');
        end;
      end;
      exitStatus := P.ExitStatus;
      { read what's left over in stdout }
      repeat
        StdOutput.SetSize(StdOutBytesRead + READ_BYTES);
        nOut := P.Output.Read((StdOutput.Memory + StdOutBytesRead)^,
READ_BYTES);
        if nOut > 0 then begin
          Inc(StdOutBytesRead, nOut);
        end;
      until nOut <= 0;
      { read what's left over in stderr }
      repeat
        StdError.SetSize(StdErrBytesRead + READ_BYTES);
        nErr := P.Stderr.Read((StdError.Memory + StdErrBytesRead)^, READ_BYTES);
        if nErr > 0 then begin
          Inc(StdErrBytesRead, nErr);
        end;
      until nErr <= 0;
      StdOutput.SetSize(StdOutBytesRead);
      if Assigned(stdout) then begin
        stdout.LoadFromStream(StdOutput);
      end;
      StdError.SetSize(StdErrBytesRead);
      if Assigned(stderr) then begin
        stderr.LoadFromStream(StdError);
      end;
    finally
      FreeAndNil(StdOutput);
      FreeAndNil(StdError);
      FreeAndNil(P);
    end;
  except
    on E : Exception do begin
      exitStatus := -1;
      if Assigned(stderr) then begin
        stderr.Add(E.Message);
      end;
    end;
  end;
end;

-SG

========================
Computer over. Virus = very yes.

Seth Grover
sethdgrover[at]gmail[dot]com
http://grovergamut.blogspot.com

2008/10/8 wile64 :

Show quoted text 55 lines
2008/10/8 wile64 > > > 2008/10/8 Vincent Snijders >> >> wile64 schreef: >> > Hi all, >> > >> > Je voudrais lancer un programme en ligne de commande (avec Tprocess ps >> > de probl?me). >> > >> > I would run an progam in command line (with Tprocess no problem). >> > >> > 1 - But with the recovery of messages for viewing in a TMemo. >> > 2 - Do not block my application when read the data (the example of a >> > wiki is awaiting data and read after) >> > 3 - Send orders. (I think a TInput.write but it does not). >> > >> > Is it possible ? >> > >> > >> >> Yes, look at the last example in the wiki: >> >> http://wiki.lazarus.freepascal.org/Executing_External_Programs#Using_input_and_output_of_a_TProcess >> > > Thanks Vincent, > > This link dead this morning ! This work, but not with the program launched :-( It's posible an program (C++) not use stdin and stdout for create console ? Thanks -- Laurent. "If debugging is the art of removing bugs, then programming must be the art of creating!" My Components: http://wiki.lazarus.freepascal.org/Wile64 French Forum : http://lazforum-fr.tuxfamily.org/index.php _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Seth Grover
to Seth Grover

oops, forgot my constant:

const
   READ_BYTES = 2048;

-SG

========================
Computer over. Virus = very yes.

Seth Grover
sethdgrover[at]gmail[dot]com
http://grovergamut.blogspot.com

Seth Grover wrote 171 lines
At one point I used this function: procedure ExecCommand(const command : string; stdout : TStringList; stderr : TStringList; const timeoutSec : integer; out exitStatus : integer); var P: TProcess; nOut : LongInt; nErr : LongInt; StdOutput : TMemoryStream; StdOutBytesRead: LongInt; StdError : TMemoryStream; StdErrBytesRead: LongInt; startTime : TDateTime; begin exitStatus := -1; StdOutput := TMemoryStream.Create; StdError := TMemoryStream.Create; StdOutBytesRead := 0; StdErrBytesRead := 0; try P := TProcess.Create(nil); try P.CommandLine := command; P.Options := [poUsePipes]; startTime := now; P.Execute; { read stderr and stdout while the process runs } while P.Running do begin StdOutput.SetSize(StdOutBytesRead + READ_BYTES); StdError.SetSize(StdErrBytesRead + READ_BYTES); nOut := P.Output.Read((StdOutput.Memory + StdOutBytesRead)^, READ_BYTES); if nOut > 0 then begin Inc(StdOutBytesRead, nOut); end; nErr := P.Stderr.Read((StdError.Memory + StdErrBytesRead)^, READ_BYTES); if nErr > 0 then begin Inc(StdErrBytesRead, nErr); end; if (nErr = 0) and (nOut = 0) then Sleep(100); if (timeoutSec > 0) and (SecondsBetween(now, startTime) > timeoutSec) then begin P.Terminate(exitStatus); raise Exception.Create('Execution timed out'); end; end; exitStatus := P.ExitStatus; { read what's left over in stdout } repeat StdOutput.SetSize(StdOutBytesRead + READ_BYTES); nOut := P.Output.Read((StdOutput.Memory + StdOutBytesRead)^, READ_BYTES); if nOut > 0 then begin Inc(StdOutBytesRead, nOut); end; until nOut <= 0; { read what's left over in stderr } repeat StdError.SetSize(StdErrBytesRead + READ_BYTES); nErr := P.Stderr.Read((StdError.Memory + StdErrBytesRead)^, READ_BYTES); if nErr > 0 then begin Inc(StdErrBytesRead, nErr); end; until nErr <= 0; StdOutput.SetSize(StdOutBytesRead); if Assigned(stdout) then begin stdout.LoadFromStream(StdOutput); end; StdError.SetSize(StdErrBytesRead); if Assigned(stderr) then begin stderr.LoadFromStream(StdError); end; finally FreeAndNil(StdOutput); FreeAndNil(StdError); FreeAndNil(P); end; except on E : Exception do begin exitStatus := -1; if Assigned(stderr) then begin stderr.Add(E.Message); end; end; end; end; -SG ======================== Computer over. Virus = very yes. Seth Grover sethdgrover[at]gmail[dot]com http://grovergamut.blogspot.com 2008/10/8 wile64 : > > > 2008/10/8 wile64 >> >> >> 2008/10/8 Vincent Snijders >>> >>> wile64 schreef: >>> > Hi all, >>> > >>> > Je voudrais lancer un programme en ligne de commande (avec Tprocess ps >>> > de probl?me). >>> > >>> > I would run an progam in command line (with Tprocess no problem). >>> > >>> > 1 - But with the recovery of messages for viewing in a TMemo. >>> > 2 - Do not block my application when read the data (the example of a >>> > wiki is awaiting data and read after) >>> > 3 - Send orders. (I think a TInput.write but it does not). >>> > >>> > Is it possible ? >>> > >>> > >>> >>> Yes, look at the last example in the wiki: >>> >>> http://wiki.lazarus.freepascal.org/Executing_External_Programs#Using_input_and_output_of_a_TProcess >>> >> >> Thanks Vincent, >> >> This link dead this morning ! > > This work, but not with the program launched :-( > > It's posible an program (C++) not use stdin and stdout for create console ? > > Thanks > > > -- > Laurent. > > "If debugging is the art of removing bugs, then programming must be the art > of creating!" > > My Components: http://wiki.lazarus.freepascal.org/Wile64 > French Forum : http://lazforum-fr.tuxfamily.org/index.php > > _______________________________________________ > Lazarus mailing list > > http://www.lazarus.freepascal.org/mailman/listinfo/lazarus > >

Reply by email

wile64
to wile64: 2008/10/8 wile64 This work, but not with the program launched :-( It's posible an program…
Show quoted text 9 lines
This work, but not with the program launched :-( It's posible an program (C++) not use stdin and stdout for create console ? Thanks

I have responce :-)

If this test don't work in command line "progam >output.txt", not work in Tprocess (idem for input)

Laurent. "If debugging is the art of removing bugs, then programming must be the art of creating!" My Components: http://wiki.lazarus.freepascal.org/Wile64 French Forum : http://lazforum-fr.tuxfamily.org/index.php -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20081008/07481b64/attachment.html

Reply by email

Henry Vermaak
to wile64
wile64 wrote
I have responce :-) If this test don't work in command line "progam >output.txt", not work in Tprocess (idem for input)

things like re-direction of output and globbing is a feature of your shell and it won't be interpreted by the tprocess. this is a common mistake people make with tprocess.

henry

Reply by email