Recent

Author Topic: Similar JvCreateProcess component ?  (Read 4007 times)

Nico83500

  • Newbie
  • Posts: 4
Similar JvCreateProcess component ?
« on: May 11, 2018, 10:43:03 pm »
Hi,
I'm a Delphi + JVCL user and I would like to try Lazarus but I often use TJvCreateProcess component from JEDI.
This component permits to launch an external process, get output from this process and wait it to finish before continue.
Is there a similar component in Lazarus ?
Thank you !

wp

  • Hero Member
  • *****
  • Posts: 11923

Nico83500

  • Newbie
  • Posts: 4
Re: Similar JvCreateProcess component ?
« Reply #2 on: May 11, 2018, 11:34:53 pm »
Thank you.
Is it possible to redirect output from process to TMemo or other text component in real time ? And is it possible to use also WaitOnExit ?
I've seen RunCommand, is it better to use it instead of TProcess ?
Thank you.

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Similar JvCreateProcess component ?
« Reply #3 on: May 12, 2018, 01:26:18 am »
Did you read the link that I gave you?

RunCommand is nothing else than a wrapper around TProcess. With TProcess you have more options.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: Similar JvCreateProcess component ?
« Reply #4 on: May 12, 2018, 08:26:41 am »
hello,
Thank you.
Is it possible to redirect output from process to TMemo or other text component in real time ? And is it possible to use also WaitOnExit ?
I've seen RunCommand, is it better to use it instead of TProcess ?
Thank you.
you have better than TProcessTProcessEx in the unit ProcessUtils
Example under windows to have the result of a ping in realtime in a Tmemo :
Code: Pascal  [Select][+][-]
  1. uses
  2.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  3.   LazUtf8,Processutils;
  4.  
  5. type
  6.  
  7.   { TForm1 }
  8.  
  9.   TForm1 = class(TForm)
  10.     Bt_Go: TButton;
  11.     Bt_GoEx: TButton;
  12.     MemConsole: TMemo;
  13.     procedure Bt_GoExClick(Sender: TObject);
  14.   private
  15.  
  16.   public
  17.     procedure ProcessOutput(Sender:TProcessEx; output:string);
  18.     procedure ProcessError(Sender:TProcessEx; {%H-}IsException:boolean);
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. {$R *.lfm}
  27.  
  28. { TForm1 }
  29.  
  30. procedure TForm1.Bt_GoExClick(Sender: TObject);
  31. var Proc: TProcessEx;
  32. begin
  33.    try
  34.    Proc := TProcessEx.Create(nil);
  35.    Proc.Executable := 'cmd.exe';
  36.    Proc.Parameters.Add('/C');
  37.    Proc.Parameters.Add('ping.exe 127.0.0.1');
  38.    Proc.OnErrorM:=@(ProcessError);
  39.    Proc.OnOutputM:=@(ProcessOutput);
  40.    Proc.Execute();
  41.    finally
  42.      Proc.Free;
  43.    end;
  44.  
  45. end;
  46.  
  47. procedure TForm1.ProcessError(Sender: TProcessEx; IsException: boolean);
  48. begin
  49.    MemConsole.Lines.Append('Erreur ! ' + Sender.ExceptionInfo);
  50. end;
  51.  
  52. procedure TForm1.ProcessOutput(Sender: TProcessEx; output : String);
  53. begin
  54.  MemConsole.Lines.Text :=  MemConsole.Lines.Text + output;
  55.   // si vous avez des problème d'accent
  56.   //MemConsole.Lines.Text := MemConsole.Lines.Text + ConsoleToUtf8(output);  
  57.   // pour scroll automatique
  58.   MemConsole.SelStart := Length(MemConsole.Lines.Text)-1;
  59.   MemConsole.SelLength:=0;
  60. end;
  61.  
  62. end.
  63.  

Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Nico83500

  • Newbie
  • Posts: 4
Re: Similar JvCreateProcess component ?
« Reply #5 on: May 12, 2018, 11:21:29 am »
Thank you, I'll try that ;)

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Similar JvCreateProcess component ?
« Reply #6 on: May 12, 2018, 02:05:48 pm »
Where can the unit ProcessUtils be found?

balazsszekely

  • Guest
Re: Similar JvCreateProcess component ?
« Reply #7 on: May 12, 2018, 03:52:46 pm »
@howardpc
Quote
Where can the unit ProcessUtils be found?
Apparently is part of fpcup/fpcupdeluxe: https://bitbucket.org/reiniero/fpcup/src

Nico83500

  • Newbie
  • Posts: 4
Re: Similar JvCreateProcess component ?
« Reply #8 on: May 12, 2018, 04:48:14 pm »
How can I add the unit ProcessUtils to my Lazarus IDE ?

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Similar JvCreateProcess component ?
« Reply #9 on: May 12, 2018, 04:54:09 pm »
you have better than TProcessTProcessEx in the unit ProcessUtils
What is the advantage of TProcessEx in comparison with TProcess?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11458
  • FPC developer.
Re: Similar JvCreateProcess component ?
« Reply #10 on: May 12, 2018, 05:01:18 pm »
It seems to be an old wrapper around tprocess.  Some things were implemented in TProcess since, so it is unclear if it still has benefits.

I think the separate procedures were combined with similar ones that I had and that became RunCommand.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: Similar JvCreateProcess component ?
« Reply #11 on: May 12, 2018, 05:32:48 pm »
you have better than TProcessTProcessEx in the unit ProcessUtils
What is the advantage of TProcessEx in comparison with TProcess?
it is true that it is an old wrapper, but the advantage , it is the management of realtime output with custom procedures. No need to add the code that it is in the wiki Executing External Process : How to redirect output with TProcess.
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: Similar JvCreateProcess component ?
« Reply #12 on: May 12, 2018, 05:47:45 pm »
How can I add the unit ProcessUtils to my Lazarus IDE ?
get the file processutils.pas from the sources of fpcupdeluxe and put it the folder of your project.

PS : The sources of my link are more recent that the sources of the Getmem's link
« Last Edit: May 12, 2018, 05:53:21 pm by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

 

TinyPortal © 2005-2018