Hi,
I'm trying (and failing) to solve an important use-case when wrapping a CLI command. On this Windows host using Lazarus 3.2.2, I would like to
- capture the output and error stream of the program while it executes
- update the GUI with progress information about the inferior process while it's running
Researching various options, I have come to believe that
TProcess.RunCommandLoop
is the "proper" way to do this in state-of-the-art Lazarus/FPC, and I would very much like to use it to implement my solution, but I just... utterly fail to pull it off.
(That is to say, I've had a number of *partial* solutions working where I could get StdOut and StdErr into TStringlists after the process terminates and have the GUI display a spinner while waiting for the spawned process to finish, but once the text produced on either fd exceeds a certain limit (I'm guessing Windows has one for pipes, too), everything just hangs indefinitely, as expected. Yeah, I get it that this is discussed in the Wiki article about Executing Processes. HOWEVER...)
The wiki has an abbreviated example available at
https://wiki.freepascal.org/Executing_External_Programs#RunCommand_extensions - but when I try to wrap that into a complete and working reproduction of this supposed example, the compiler barfs at me with
unit1.pas(58,26) Error: Wrong number of parameters specified for call to "LocalnIdleSleep"
unit1.pas(35,27) Error: Found declaration: LocalnIdleSleep(TObject;TObject;TRunCommandEventCode;const AnsiString);
I've never created a class of my own in FPC/Lazarus before, so I might be missing some context, but... is this example just plain incorrect or at least incomplete?
I would also like to express my ample frustration with this particular part/page of the Wiki documentation - if I had the knowledge, I would happily and readily rewrite it, but I don't, hence I can't. What is wrong with it, in my humble opinion, is there there is gobs and gobs and GOBS of paragraphs that deal with this (I think) relatively common use-case, but nowhere does it state clearly what is the sanest way to do it TODAY, instead citing numerous ways for readers who are interested in the historic recounting of Pascal-esque execve() variants and "this is a way to do it, but it's wrong, and breaks if there is too much output or the moon is in the 7th house"-non-solutions. I think it is in desperate need of expert attention. I would happily donate EUR 50,- to a charity or Lazarus-affiliated organization of the author's choosing if it were to be weeded out and made clear, concise, sufficiently complete and wholly correct.