I have write a class with the last example, but when i want to start another programm my lazarus program crashed... :S
here is the sourcecode of the class:
unit cprozess;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Process, StdCtrls, Dialogs;
const
READ_BYTES = 2048;
type TProzessdata = class(TObject)
private
public
function execute_programm(prog:String):TStringlist;
end;
implementation
function TProzessdata.execute_programm(prog:String):TStringList;
var
S: TStringList;
M: TMemoryStream;
P: TProcess;
n: LongInt;
BytesRead: LongInt;
begin;
M := TMemoryStream.Create;
BytesRead := 0;
P := TProcess.Create(nil);
P.CommandLine := 'halt';
P.Options := [poUsePipes];
P.Execute;
while P.Running do
begin
M.SetSize(BytesRead + READ_BYTES);
n := P.Output.Read((M.Memory + BytesRead)^, READ_BYTES);
if n > 0 then
Inc(BytesRead, n)
else
Sleep(100);
end;
repeat
M.SetSize(BytesRead + READ_BYTES);
n := P.Output.Read((M.Memory + BytesRead)^, READ_BYTES);
if n > 0 then
Inc(BytesRead, n);
until n <= 0;
M.SetSize(BytesRead);
S := TStringList.Create;
S.LoadFromStream(M);
S.Free;
P.Free;
M.Free;
execute_programm:=S;
end;
end.
uses ..., cprozess;
...
var
Form1: TForm1;
startop:TStartup;
prozessop:TProzessdata;
...
procedure TForm1.Button1Click(Sender: TObject);
Var local: TSTringlist;
begin
local:=prozessop.execute_programm('');
memo1.lines:=local;
end;
what is wrong?