SOLVED - Gaining Output from running a process lazarus / 21-General ---------------------------------------------------------------------- zxandris · 2024-03-08 19:00 I'm using the following code and trying to gain the output from what I'm running, but it just hangs if I run it with the option to pipe the output, has anyone got any idea what I'm doing wrong please? 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 RunAndPAuse2(EXEFile, cmdline: string; const show : TShowWindowOptions; const pipe : Boolean) : String;var  AProcess: TProcess;  aStringList : TStringList;begin  // Now we will create the TProcess object, and  // assign it to the var AProcess.  AProcess := TProcess.Create(application);  try       aProcess.Executable:= exeFile;       AProcess.Parameters.text := CmdLine;        // We will define an option for when the program       // is run. This option will make sure that our program       // does not continue until the program we will launch       // has stopped running.        AProcess.Options := [];       if pipe then  AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes]       else AProcess.Options := AProcess.Options + [poWaitOnExit];        AProcess.ShowWindow := Show;        // Now that AProcess knows what the commandline is       // we will run it.       AProcess.Execute;      if Pipe then       begin            // Now read the output of the program we just ran into a TStringList.            AStringList := TStringList.Create;            try               AStringList.LoadFromStream(AProcess.Output);               // Save the output to a file and clean up the TStringList.               // debugLog(AStringList.text);               result := AStringList.text;            finally                   AStringList.Free;            end;      end else Result := '';  finally         AProcess.Free;  end;end; ---------------------------------------------------------------------- marcov · 2024-03-08 19:02 Not using runcommand ? https://www.freepascal.org/docs-html/fcl/process/runcommand.html ---------------------------------------------------------------------- Thaddy · 2024-03-08 19:44 What you are doing wrong is just not reading the documentation. (not the wiki, but the documentation) The solution Marco mentioned is better and has been there for some time. Re-inventing wheels as a hexagon is never a good idea. It is bumpy. ---------------------------------------------------------------------- zxandris · 2024-03-08 20:21 That would be great but according to the compiler the runcommand is depreciated, so I was hoping to come up with another solution... ---------------------------------------------------------------------- TRon · 2024-03-08 20:28 Quote from: zxandris on March 08, 2024, 09:21:12 pmThat would be great but according to the compiler the runcommand is depreciated, so I was hoping to come up with another solution... *sight* (this has been asked and answered a couple of times before you asked  ) Try to read the article in the link carefully... and note QuoteThe version using CmdLine attempts to split the command line in a binary and separate command-line arguments. This version of the function is deprecated. Meaning, that that particular version of the function, and only that particular version of the function is deprecated. So, the other one is not deprecated Do the help files support bold, underlined, choosing a bigger and colored font ? *hint* ---------------------------------------------------------------------- Thaddy · 2024-03-08 20:35 Or ---------------------------------------------------------------------- bytebites · 2024-03-08 20:50 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 RunCommand(   const cmdline: TProcessString;   out outputstring: string ):Boolean; deprecated; ---------------------------------------------------------------------- TRon · 2024-03-08 20:50 @Thaddy I have a notion that it might be more frustrating for marcov to read such (wrong) assumptions because he spend all that time perfecting the function. ---------------------------------------------------------------------- zxandris · 2024-03-09 04:14 I'll put my hands up here, I should've looked more closely into that.  That's my bad, sorry.  I saw the message from the compiler and sort of paniced, lol. I've looked into that properly now and have solved my issue. Thanks guys, CJ ---------------------------------------------------------------------- zxandris · 2024-03-09 04:26 I just realised for those that come next, there was no actual solve posted.  So, in the interests of that here's what I used in the end from the advice given :- 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(cmdLine, cline, output, [poWaitOnExit, poNoConsole, poUsePipes], swoHide);  That ran my external exe, hidden and got the output I wanted, where cmdLine was the exe and cline was an array of TProcessString.  I had to convert from a string list as that's how I had that before hand. For anyone with the same problem, I hope this helps.