Unable to `RunCommand('/bin/ps',['-eo','pmem,rss,pid,command'], psOut)` on macos lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- d-_-b · 2019-05-31 17:23 Hi, I believe the following code should just work? But Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i RunCommand('/bin/ps',['-eo','pmem,rss,pid,command'], psOut) always return Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i False. Any suggestions? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program runcmd_ps; {$mode objfpc}{$H+} uses  {$IFDEF UNIX}{$IFDEF UseCThreads}  cthreads,  {$ENDIF}{$ENDIF}  Classes, SysUtils, CustApp,  process  { you can add units after this }; type   { TMyApplication }   TMyApplication = class(TCustomApplication)  protected    procedure DoRun; override;  public    constructor Create(TheOwner: TComponent); override;    destructor Destroy; override;    procedure WriteHelp; virtual;  end; { TMyApplication } procedure TMyApplication.DoRun;var  ErrorMsg, psOut: String;begin  // quick check parameters  ErrorMsg:=CheckOptions('h', 'help');  if ErrorMsg<>'' then begin    ShowException(Exception.Create(ErrorMsg));    Terminate;    Exit;  end;   // parse parameters  if HasOption('h', 'help') then begin    WriteHelp;    Terminate;    Exit;  end;   // if not RunCommand('/bin/ps',['-eo','pmem,rss,pid,command'], psOut) then begin // thanks Hansaplast  if RunCommand('/bin/ps',['-eo','pmem,rss,pid,command'], psOut) then begin      writeln(psOut)  end;   // stop program loop  Terminate;end; constructor TMyApplication.Create(TheOwner: TComponent);begin  inherited Create(TheOwner);  StopOnException:=True;end; destructor TMyApplication.Destroy;begin  inherited Destroy;end; procedure TMyApplication.WriteHelp;begin  { add your help code here }  writeln('Usage: ', ExeName, ' -h');end; var  Application: TMyApplication;begin  Application:=TMyApplication.Create(nil);  Application.Title:='My Application';  Application.Run;  Application.Free;end. ---------------------------------------------------------------------- d-_-b · 2019-06-01 10:11 Mmm, I seem to be corrected, because I broke the above problem to a test program and it seems to work with a basic TCustomApplication code path. But in my more advance fptuitreemap.pas codebase it still fails my 'test ps list for macos...' test??! ---------------------------------------------------------------------- Hansaplast · 2019-06-01 10:11 I think you have to remove the "not" in line 47? Maybe you overlooked that one ...? I just did a little test and this works correctly; Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1;  {$mode objfpc}{$H+}  interface  uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, process;  type    { TForm1 }    TForm1 = class(TForm)    Button1: TButton;    Memo1: TMemo;    procedure Button1Click(Sender: TObject);  private    public    end;  var  Form1: TForm1;  implementation  {$R *.lfm}  { TForm1 }  procedure TForm1.Button1Click(Sender: TObject);var  s:ansistring;begin  if RunCommand('/bin/ps',['-eo','pmem,rss,pid,command'], s) then    Memo1.Text:=s;end;  end.         RunCommand returns True if the function executed successfully. I'm running MacOS Mojave 10.14.5, and Lazarus 2.1.0 r61306M FPC 3.0.4 x86_64-darwin-cocoa (alpha) (from trunk). ---------------------------------------------------------------------- d-_-b · 2019-06-01 10:16 Quote from: Hansaplast on June 01, 2019, 12:11:43 pmI think you have to remove the "not" in line 47? Thanks yes that was the issue in my example *doh*. But please see my more advance issue. I'm going to add more of my tui code to the test case until runcommand start to fail for me again or I end up with a working example. Thanks for having a look, ---------------------------------------------------------------------- Hansaplast · 2019-06-01 11:28 Happens to the best of us and happy to help when I can    ... As for your more advanced code,... not sure what to tell you there. It all looks OK. I even tested it with Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   if not RunCommand('/bin/ps',['-eo','pmem,rss,pid,command'], s) then    Memo1.Text:='FAIL'  else    Memo1.Text:=s; and (invalid command) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   if not RunCommand('/bin/psbad',['-eo','pmem,rss,pid,command'], s) then    Memo1.Text:='FAIL'  else    Memo1.Text:=s; and (invalid parameters) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   if not Ru nCommand('/bin/ps',['- eoasldjaghsikafgladgfakls','pmem,rss,pid,command'], s) then    Memo1.Text:='FAIL'  else    Memo1.Text:=s; and they all work as expected, but then again, I'm not very familiar with TCustomApplication. ---------------------------------------------------------------------- d-_-b · 2019-06-02 20:16 Eureka! While the drawing might be broken in the gitlab-runner output it means RunCommand could execute! But I don't know were the problem was except between keyboard and chair. I actually think my understanding of {IFDEF} blocks for OS detection might have been wrong. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     {$IFDEF UNIX}    {$IFDEF DARWIN} // mac - powerpc & intel based      psArg0 := '-eo';      psArg1 := 'pmem,rss,pid,command';    {ELSE} // same as IFDEF LINUX?      psArg0 := '-eo';      psArg1 := 'pmem,rss,pid,cmd';    {$ENDIF}  That "same as IFDEF LINUX?" seems not to be true so I passed `psArg1 := 'pmem,rss,pid,cmd';` to `ps` and then RunCommand failed because `ps` on macos wants `command` not `cmd`. This is speculation. Because as mentioned after reworking my code it works. Hansaplast thanks for your input! ---------------------------------------------------------------------- Hansaplast · 2019-06-02 20:41 Cool!  Ehm just wondering if this shouldn't look more like so: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   {$IFDEF UNIX}      {$IFDEF DARWIN} // mac - powerpc & intel based          psArg0 := '-eo';          psArg1 := 'pmem,rss,pid,command';      {$ELSE} // same as IFDEF LINUX?          psArg0 := '-eo';          psArg1 := 'pmem,rss,pid,cmd';      {$ENDIF}  {$ENDIF} I tried to find a wiki link, but somehow this page turns up blank? Google Cache still has it here.