[fpc-pascal] Re: tstringlist.savetostream
Terry A. Haimann
terry at HaimannOnline.com
Wed Mar 17 00:08:09 CET 2010
Ok, I have a Lazarus test program that has the following code:
procedure TMainForm.ExecButClick(Sender: TObject);
Var
StdStrLst, ErrorStrLst: TStringList;
MyProcess: TProcess;
begin
StdStrLst := TStringlist.Create;
ErrorStrLst := TStringlist.Create;
MyProcess := TProcess.Create(nil);
MyProcess.CommandLine := 'at -m ' + TimeEdit.Text;
MyProcess.Options := MyProcess.Options + [poUsePipes];
MyProcess.Execute;
StdStrLst.Clear;
StdStrLst.Add(CmdEdit.Text);
StdStrLst.SaveToStream(MyProcess.Input);
StdStrLst.Clear;
StdStrLst.Add(chr(4));
StdStrLst.SaveToStream(MyProcess.Input);
StdStrLst.Destroy;
ErrorStrLst.Destroy;
MyProcess.Destroy;
end;
This program seems to submit commands to the At Facility without any
issues. They will even run invalid commands and return error messages
in the mail command.
Virtually the same logic in a fpc program doesn't work. The program
runs, but nothing is submitted to the "AT" facility. I am suspecting
something is requiring one of the libraries in Lazarus that I can't seem
to get to compile in fpc such as fileutil, LResources or maybe
Controls. But I may be missing something else. Something could be
going on with the pipes that I don't understand. I don't know of a way
to monitor the pipes or the "AT" Facility to see what is going on. I am
running FC10-64
program TestPrg;
Uses Classes, Process, SysUtils;
// Uses Classes, SysUtils, fileutil, LResources, Forms, Controls,
Graphics, Dialogs,
// StdCtrls, Process;
Var
i: Integer;
Cmd, Pre, Post, StrVar, SwStr: String;
MyProcess: TProcess;
SOut, EOut, StdStrLst: TStringList;
Begin
StdStrLst := TStringlist.Create;
SOut := TStringlist.Create;
EOut := TStringlist.Create;
MyProcess := TProcess.Create(nil);
MyProcess.CommandLine := 'at -m now';
MyProcess.Options := MyProcess.Options + [poUsePipes];
MyProcess.Execute;
StdStrLst.Clear;
StdStrLst.Add('awk -F":" ''{print $1"\t"$3"\t"$4}'' /etc/passwd |
sort > /home/terry/Documents/fpc/CommandProg/Output.txt');
StdStrLst.SaveToStream(MyProcess.Input);
StdStrLst.Clear;
StdStrLst.Add(chr(4));
StdStrLst.SaveToStream(MyProcess.Input);
SOut.LoadFromStream(MyProcess.Output);
For i:=1 to SOut.Count Do
WriteLn(SOut.Strings[i]);
EOut.LoadFromStream(MyProcess.StdErr);
For i:=1 to EOut.Count Do
WriteLn(EOut.Strings[i]);
End.
More information about the fpc-pascal
mailing list