Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2021-10

Process differences

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Steve Gatenby

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

Reply by email

Juha Manninen
to Steve Gatenby

On Tue, Oct 19, 2021 at 7:58 AM Steve Gatenby via lazarus <

Show quoted text 5 lines
wrote: Hoping someone could shed some light on why different results on the following code :)

My guess is that a GTK2 session adjusts user and group rights somehow. When I run your command 'ps -eo pid:1,cpu:1,cgroup' in a console, I get many output lines. Very different from your output. I did not study what the parameters do exactly.

Juha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20211019/ca646e8e/attachment.html>

Reply by email

Denis Kozlov
to Steve Gatenby: Hoping someone could shed some light on why different results on the following code :)…

On Tue, 19 Oct 2021 at 05:58, Steve Gatenby via lazarus <

Show quoted text 5 lines
wrote: Hoping someone could shed some light on why different results on the following code :)

There is a peculiar truncation at around 80 characters in your second example. The output might be getting broken down into multiple lines.

You might want to inspect the raw content of the sData variable before dumping it into a text file.

Also, try changing this line:

slTemp.Add(sData);

To this line:

slTemp.Text := sData;

Denis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20211019/c826f6b8/attachment.html>

Reply by email

Steve Gatenby

(mis-directed earlier reply - sorry about that)

Thanks Denis - will try that.

will also check my user rights as Juha suggested as well

gotta be something my end :)

Denis Kozlov wrote 20 lines
On Tue, 19 Oct 2021 at 05:58, Steve Gatenby via lazarus wrote: Hoping someone could shed some light on why different results on the following code :) There is a peculiar truncation at around 80 characters in your second example. The output might be getting broken down into multiple lines. You might want to inspect the raw content of the sData variable before dumping it into a text file. Also, try changing this line: > slTemp.Add(sData); To this line: > slTemp.Text := sData; Denis

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20211021/de002e89/attachment.html>

Reply by email