[Lazarus] Process differences

Steve Gatenby steveg at nevets.com.au
Tue Oct 19 06:58:19 CEST 2021


Hoping someone could shed some light on why different results on the 
following code :)


Example 1 - simple fpc app (as below) - works as expected - full output 
to text file

program project1;
uses Classes, SysUtils, Process;

var
   sData        :ansistring;
   slTemp    :TStringList = NIL;
begin

     RunCommand('/bin/bash', ['-c', 'ps -eo pid:1,cpu:1,cgroup' ], sData);

     slTemp := TStringList.Create;
     try

       slTemp.Add(sData);

       slTemp.SaveToFile('/home/steveg/out-1.txt');

     finally
       FreeAndNil(slTemp);
     end;

end.

sample output line from text file -

425 - 
12:devices:/system.slice/systemd-udevd.service,11:memory:/system.slice/systemd-udevd.service,9:pids:/system.slice/systemd-udevd.service,6:blkio:/system.slice/systemd-udevd.service,3:cpu,cpuacct:/system.slice/systemd-udevd.service,1:name=systemd:/system.slice/systemd-udevd.service,0::/system.slice/systemd-udevd.service[LF]

-------------------------------------------------------------------------------------------------


Example 2 - basic lazarus gui app (linux gtk2) - same code as above, 
called on button press

this one truncates output lines in file ?

procedure TForm1.Button1Click(Sender: TObject);
var
   sData        :ansistring;
   slTemp    :TStringList = NIL;
begin

     RunCommand('/bin/bash', ['-c', 'ps -eo pid:1,cpu:1,cgroup' ], sData);

     slTemp := TStringList.Create;
     try

       slTemp.Add(sData);

       slTemp.SaveToFile('/home/steveg/out-2.txt');

     finally
       FreeAndNil(slTemp);
     end;

end;

sample (same) output line from text file -

425 - 
12:devices:/system.slice/systemd-udevd.service,11:memory:/system.slice/sys[LF]


any suggestions definitely appreciated :)

Regards - SteveG




More information about the lazarus mailing list