Recent

Author Topic: Displaying progress of shell messages in a memo - how?  (Read 4676 times)

Amnon82

  • New Member
  • *
  • Posts: 37
Displaying progress of shell messages in a memo - how?
« on: April 01, 2007, 01:29:15 pm »
I'm writing an installer for a linux distribution.

I'm running sh-scripts for coping files.
Now I want to display the progress of the running sh-script
in a memo or listbox.

For doing that I need a function to display the GUI messages
without freezing the GUI.

What will the best way to do that?

Amnon82

  • New Member
  • *
  • Posts: 37
RE: Displaying progress of shell messages in a memo - how?
« Reply #1 on: April 01, 2007, 04:20:08 pm »
The freezing I solved in this code:

Code: [Select]
//Processandwait example by Amnon82
//Version 20070312-1
//
//Create a form with one button on it.
//Copy this sourcecode to your pas.
//Compile it in lazarus.


unit unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Buttons, Process;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{ TForm1 }

procedure Processandwait(Executable : String);
var
  AProcess1: TProcess;
  exitcode, i  : integer;
begin
  I:= 0;
  try
  AProcess1 := TProcess.Create(nil);
  AProcess1.CommandLine := Executable;
  AProcess1.Options := AProcess1.Options;
 
 {Execute}
  AProcess1.Execute;
  {Wait to finish}
  while AProcess1.running = true do
  begin
  I:= I + 1;
  sleep (300);
  form1.caption :=  ' L:'+ inttostr(i);
   Application.ProcessMessages;
  end;
 
  finally
    AProcess1.Free;
    end;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin

 Processandwait('gedit');
 Showmessage('gedit closed');
end;

initialization
  {$I unit1.lrs}

end.      


now I must find a way to get the messages of the external app into a memo/listbox.

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1946
RE: Displaying progress of shell messages in a memo - how?
« Reply #2 on: April 01, 2007, 04:35:51 pm »

Amnon82

  • New Member
  • *
  • Posts: 37
RE: Displaying progress of shell messages in a memo - how?
« Reply #3 on: April 01, 2007, 05:12:48 pm »
I readed it. I need a option to display the progress of unsquashing a image in a memo. So it must be displayed during the excution.

Amnon82

  • New Member
  • *
  • Posts: 37
RE: Displaying progress of shell messages in a memo - how?
« Reply #4 on: April 01, 2007, 06:55:08 pm »
I got it displayed but the memo dosn't scroll. Why? I used ssAutoBoth and ssAutoVertical:

Code: [Select]
//Processandwait example by Amnon82
//Version 20070312-1
//
//Create a form with one button on it.
//Copy this sourcecode to your pas.
//Compile it in lazarus.


unit unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Buttons, Process,
  StdCtrls, DbCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    DBMemo1: TDBMemo;
    Edit1: TEdit;
    GroupBox1: TGroupBox;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    procedure Button1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{ TForm1 }

procedure Processandwait(Executable : String);
var
  AProcess1: TProcess;
  exitcode, i  : integer;
  AStringList: TStringList;

begin
  I:= 0;
  AStringList := TStringList.Create;
  try
  AProcess1 := TProcess.Create(nil);
  AProcess1.CommandLine := Executable;
  AProcess1.Options := AProcess1.Options+ [poUsePipes];

 {Execute}
  AProcess1.Execute;
  {Wait to finish}
  while AProcess1.running = true do
  begin
  form1.button1.enabled:=false;
  //I:= I + 1;
  AStringList.LoadFromStream(AProcess1.Output);
  if form1.radiobutton2.checked= true
  then
  Form1.dbmemo1.lines.add(Astringlist.text)
    else
  form1.edit1.text:=Astringlist.text;
  sleep (400);
  Application.ProcessMessages;
  end;
  finally
     AStringList.LoadFromStream(AProcess1.Output);
  if form1.radiobutton2.checked=true
  then
  Form1.dbmemo1.lines.add(Astringlist.text);
    AProcess1.Free;
    AStringlist.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin

 if radiobutton2.checked=true then
 Processandwait('sudo ./copypaldo.sh')
 else
 Processandwait('sudo ./gettable2.sh') ;
 button1.enabled:=true;
 showmessage('done');

end;

initialization
  {$I unit1.lrs}

end.      

 

TinyPortal © 2005-2018