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

Just starting out? Need help? Post your questions and find answers here.
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

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

Post 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.
Last edited by boddhi on Sat Feb 17, 2024 1:30 pm, edited 1 time in total.
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
infratec
Always Here
Always Here
Posts: 7663
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Technical question about RunProgram() and related functions

Post 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.
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Technical question about RunProgram() and related functions

Post 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...
 
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
infratec
Always Here
Always Here
Posts: 7663
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Technical question about RunProgram() and related functions

Post 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:
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Technical question about RunProgram() and related functions

Post 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:
 
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
Post Reply