Page 1 of 1

[ANSWERED] Technical question about RunProgram() and related functions

Posted: Fri Feb 16, 2024 2:43 pm
by boddhi
Hello,

I'm writing a single procedure that handles a few commands (a, x and l) of 7z.exe for the exploitation of more than 100k archives.

There's a question on my mind: Does multiplying the test lines within a 'While ProgramRuning()' and processing the retrieved strings with ReadProgramString() somehow slow down the execution of 7z and, more generally, any program run in this way?

I'm wondering whether I should create a procedure for each type of 7z command (with redundant tests and processing) or a single procedure with all the tests and processing.

As you can see, the aim of all this is to make the procedure(s) run as quickly as possible.

Thanks.

Re: Technical question about RunProgram() and related functions

Posted: Sat Feb 17, 2024 10:42 am
by infratec
In general it should not slow down your external program.

The program writes to stdout or stderr. These devices are buffered and writing does not block.

But you should not use ReadProgramString()
Use ReadProgramData() instead, with the AvailableProgamOutput() length.

Re: Technical question about RunProgram() and related functions

Posted: Sat Feb 17, 2024 11:59 am
by boddhi
Hello Infratec,

Thanks for your reply.
That's what I thought, but it removes any doubt.

But... it also raised another question:
infratec wrote: But you should not use ReadProgramString()
Use ReadProgramData() instead, with the AvailableProgamOutput() length.
Why should ReadProgramData() be preferred to ReadProgramString() if the latter exists?
The data retrieved are simple text strings (non-binary data). It seems simpler to me, but maybe I'm wrong...
 

Re: Technical question about RunProgram() and related functions

Posted: Sat Feb 17, 2024 12:48 pm
by infratec
ReadProgramString() blocks your code. If there comes something on stderr, you don't read it until the stdout line is completed.
And if you get a process progess via xx% you get no CRLF, because this is done via BS or via cursor movement.
So you don't get the progress.

I only use ReadProgramString() if I 100% know how the other program makes his output.
Normally when the program is from me :wink:

Re: Technical question about RunProgram() and related functions

Posted: Sat Feb 17, 2024 1:29 pm
by boddhi
Thanks for the technical information, which I'll take into consideration. :wink:

I'm not very familiar with the use of RunProgram() but all the times I've used it, I've never had a problem. So I just kept on doing it that way. :mrgreen: