Having trouble with TProcess and RunCommand on Windows lazarus / 34-Windows ---------------------------------------------------------------------- rail5 · 2021-12-24 03:28 I should say I haven't used Windows for something like ten years, so I'm a bit lost trying to solve this one on my own The problem I'm having is something like this: 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('liesel', Options, ReturnString) (where "liesel" is a cross-platform binary on both Windows & Linux, and "Options" is a TStringArray containing elements like '-i', 'some- input-path', '-g', '-v', '-o', 'some-output-path') Runs just fine on Linux hosts, but fails on Windows with no error message & no execution Conversely, 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('liesel', ['-h'], ReturnString) Runs just fine on both systems Likewise, 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 Process1 := TProcess.Create(nil);Process1.Executable := 'liesel'; for i := 0 to (Length(Options)-1) dobegin  Process1.Parameters.Add(Options[i]);end; Process1.Options := [poUsePipes];Process1.Execute; Runs just fine on Linux, but doesn't run at all on Windows Is there something (as I'm hoping there is) incredibly obvious that I'm missing? Thanks ---------------------------------------------------------------------- trev · 2021-12-24 05:03 Check what you have against the declaration: 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 exename: TProcessString;  const commands: array of TProcessString;  out outputstring: string;  Options: TProcessOptions = [];  SWOptions: TShowWindowOptions = swoNone):Boolean; It might also be worth adding error checking on the boolean return status which is currently ignored. ---------------------------------------------------------------------- rail5 · 2021-12-24 05:37 Quote from: trev on December 24, 2021, 06:03:29 amCheck what you have against the declaration: 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 exename: TProcessString;  const commands: array of TProcessString;  out outputstring: string;  Options: TProcessOptions = [];  SWOptions: TShowWindowOptions = swoNone):Boolean; It might also be worth adding error checking on the boolean return status which is currently ignored. Hey thanks for the reply Well after reading your post, setting the project target OS to Win32/Win64 and then clicking "Find declaration of RunCommand / Find declaration of Process" results in: "Error: unit not found: Process" It still compiles without complaining, and I'm even more flummoxed now as to why RunCommand half-works on Windows builds if it isn't including the Process unit Tried recompiling the cross-compiler ( as per https://wiki.lazarus.fre epascal.org/Cross_compiling_for_Windows_under_Linux ), but same result ---------------------------------------------------------------------- trev · 2021-12-24 06:07 You need to add Process to your Uses clause. ---------------------------------------------------------------------- rail5 · 2021-12-24 06:32 Sorry, I wasn't clear. It's already in the Uses clause (see the screenshot) The "unit not found" error comes up when I switch the target OS to Win32 or Win64 (and yet, the project still builds) The reason I tried re-compiling the cross-compiler was that I assumed there was a Win64 "version" of the Process unit that was somehow skipped the first time. Re-compiling didn't fix it though so I'm in the dark Edit: Also, the compiler logs (from building the cross-compiler) say that the installation of 'fcl-process' was successful Further edit: /etc/fpc.cfg also contains the line: 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 -Fu/usr/lib/fpc/$fpcversion/units/$FPCTARGET/* And the "fcl-process" directory (complete with process.o, process.ppu etc) is present in both /usr/lib/fpc/3.2.0/units/x86_64-win64/ and /usr/lib/fpc/3.2.0/units/i386-win32 ---------------------------------------------------------------------- trev · 2021-12-24 08:42 Check where it's looking for the unit - turn on all messages (Lazarus > Project > Project Options > Compiler options > Verbosity - [ ] Show everything) and copy "All/Original Messages" from messages window to the clipboard at end of compilation. It will show you where it is looking for the Process unit and not finding it. ---------------------------------------------------------------------- mosquito · 2021-12-24 10:07 Just an idea, if the external executable is not on the same level of the file system, try using the executable's full path. ---------------------------------------------------------------------- rail5 · 2021-12-24 10:44 Thanks everybody for replying, and happy holidays by the way Well, the logs show that the compiler isn't having trouble finding the Process unit (+ Library + Object), so the "unit not found" bug is just isolated in the Source viewer in Lazarus 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 [1.010] (10000) Unitsearch: /usr/lib/fpc/3.2.0/units/x86_64-win64/fcl- process/process.ppu[1.010] Searching file /usr/lib/fpc/3.2.0/units/x86_64-win64/fcl-process/process.ppu... found[1.010] (10001) PPU Loading /usr/lib/fpc/3.2.0/units/x86_64-win64/fcl-process/process.ppu[1.010] (PROCESS)  (10002) PPU Name: /usr/lib/fpc/3.2.0/units/x86_64-win64/fcl-process/process.ppu[1.010] (PROCESS)  (10011) PPU Source: process.pp not available[1.010] (PROCESS)  (10011) PPU Source: processbody.inc not available[1.010] (PROCESS)  (10011) PPU Source: process.inc not available Which brings me back to square 1 -- RunCommand seems to work on Linux when: 1. provided with a TStringArray of parameters & 2. provided with an "array literal" so to speak (as in RunCommand('liesel', SomeTStringArray, ReturnString) vs. RunCommand('liesel', ['-h', '-q', '-c'], ReturnString) for example) Where on Windows, RunCommand only seems to work when provided with an "array literal," + the TProcess fails (again only on Windows) and I can't tell why (with Parameters.Add() and then Execute). (I also tried with TProcess.CommandLine just to check, and that fails as well) Is there maybe a problem on Windows just with programmatically determining those parameters as variables instead of being statically- fixed parameters (having the parameters determined at runtime instead of compile time)? The idea is for the user to select parameters from the GUI and then execute If that's it, is there a way to force the compiler to recognize that a particular variable will only be set at runtime rather than compile time? ---------------------------------------------------------------------- marcov · 2021-12-24 12:30 I use runcommand daily, so it should be something with your setup. Could you please make a complete minimal console application to give us something to test? Try to enable Delphi mode. Try also to add the full path to the exe name(e.g. c:\a\b\liesel), maybe in your application the working directory is not what you think it is.