[SOLVED] TProcess returns nothing lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- Zvoni · 2020-09-10 21:55 Hi Folks, Mojave 10.14.6 Laz/FPC fixes (2.0.11/3.2.1) How do i read the output from stdout/stdErr called through TProcess on MacOS? On Linux no problems, on Mac: Nada, njet. i'm using the usual Process-Options (NoConsole,UsePipes, ErrtoOutPut) which work on Linux. I'm using the sample from the Wiki-page (which i have running successfully on Linux) the command-line is actually "which ffprobe" (curiously: executing ffprobe in terminal on Mac works as i'm used to from Linux, using it as the executable in TProcess returns "program not found" or something.) So It's not a question if ffprobe is in PATH, since directly in the terminal it works. If i use the full path to ffprobe as my executable for TProcess it works, so i wanted to use a "which ffprobe" to return the path, but....... ---------------------------------------------------------------------- trev · 2020-09-11 01:43 TProcess does not inherit the environment variables (eg PATH) because it is not a shell; that is why you get command not found. This is what I do on macOS (Mojave): 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 DemoProcess; uses  Classes, SysUtils, Process; var  AProcess: TProcess;  AStringList: TStringList; begin  AProcess := TProcess.Create(nil);  AProcess.Executable := '/bin/sh';  AProcess.Parameters.Add('-c');  AProcess.Parameters.Add('"date"');  AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes, poStderrToOutPut];  AProcess.Execute;   AStringList := TStringList.Create;  AStringList.LoadFromStream(AProcess.Output);  AStringList.SaveToFile('output.txt');   AStringList.Free;  AProcess.Free;end. output.txt contains "Fri 11 Sep 2020 11:41:38 AEST". Note: poNoConsole is a Win32 only option. ---------------------------------------------------------------------- Jurassic Pork · 2020-09-11 06:14 hello, Quote from: Zvoni on September 10, 2020, 11:55:37 pmthe command-line is actually "which ffprobe" (curiously: executing ffprobe in terminal on Mac works as i'm used to from Linux, using it as the executable in TProcess returns "program not found" or something.) instead of using which to search the path of ffprobe you can try to use the FindDefaultExecutablePath function from FileUtil unit. Friendly, J.P ---------------------------------------------------------------------- Jonas Maebe · 2020-09-11 07:13 "which" exists both as a shell built-in and as an external program. On macOS, it is not installed as an external program by the system. As a result trying to start "which" as a separate process fails. It's the same as trying to execute "set" as an external process. You can use Trevor's workaround, but you will have to remove the "-c" because of the fact that it's not an external program, but a built-in command of the shell. ---------------------------------------------------------------------- trev · 2020-09-11 08:29 Quote from: Jonas Maebe on September 11, 2020, 09:13:33 am"which" exists both as a shell built-in and as an external program. On macOS, it is not installed as an external program by the system. My Mojave system  has a /usr/bin/which external program with same same date stamp as the uucp binary in the same directory, so it's unlikely to have been installed by a dev tool. My Leopard system also has a /usr/bin/which. ---------------------------------------------------------------------- Zvoni · 2020-09-11 15:49 Reporting back: no "-c" --> /bin/sh which ffprobe results in: cannot execute binary file --> no cigar FindDefaultExecutablePath returns empty string (no Basedir specified)-->  --> no cigar /bin/sh -c which ffprobe executes which, but disregards anything after it (options/parameters): returns "usage which [-as] program" --> no cigar Ideas? I admit: I don't have a clue about MacOS, just trying to get a program running there ---------------------------------------------------------------------- Zvoni · 2020-09-11 17:19 Solved! But Boy, what a hassle. 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 Function GetPath:String;Var  sCommand:String;  oProcess:TProcess;  oStrings:TStringList;Begin  sCommand:='sh -c '+QuotedStr('which ffprobe');  oProcess:=TProcess.Create(nil);  oProcess.Options:=[poWaitOnExit,poUsePipes,poStderrToOutPut];  oProcess.CommandLine:=sCommand;  oProcess.Execute;  oStrings:=TStringList.Create(nil);  oStrings.LoadFromStream(oProcess.OutPut);  Result:=Trim(oStrings.Text);  oStrings.Free;  oProcess.Free;End;  Funny enough: couldn't get it to work with Executable and Parameters, only with (deprecated) CommandLine (and yes: i commented it out beforehand) ---------------------------------------------------------------------- trev · 2020-09-12 00:47 No need to use the deprecated CommandLine. This works for me: 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 DemoProcess; uses  Classes, SysUtils, Process; var  AProcess: TProcess;  AStringList: TStringList; begin  AProcess := TProcess.Create(nil);   AProcess.Executable := '/bin/sh';  AProcess.Parameters.Add('-c');  AProcess.Parameters.Add('which date');  AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes, poStderrToOutPut];  AProcess.Execute;   AStringList := TStringList.Create;  AStringList.LoadFromStream(AProcess.Output);  WriteLn(AStringList.Text);   AStringList.Free;  AProcess.Free;end. produces: Quote$ ./demoprocess /bin/date