Running external program as batch file with delayed inputs

3 Ansichten (letzte 30 Tage)
Jan Knop
Jan Knop am 22 Jun. 2023
Kommentiert: Jan Knop am 23 Jun. 2023
I have created a batch file "myBatchFile.bat" of my external program and have my inputs in a seperate input file "inputs.txt" with a buch of inputs, which have to be input after another. The inputs look as follows:
input1
input2
input3
...
inputn
I'm calling the program and inputs with:
commandfileName = 'inputs.txt';
runfileName = 'myBatchFile.bat'
[~,~] = system([runfileName blanks(1) commandfileName], '-echo');
I run into the issue, that the inputs are too fast for the batch program. To avoid this issue I'd like to have a delay inbetween each input. I can't figure out how to implement that delay.
  2 Kommentare
Rik
Rik am 23 Jun. 2023
What do you mean with " the inputs are too fast for the batch program"?
And what exactly do you want to delay?
Jan Knop
Jan Knop am 23 Jun. 2023
The first input finds the program I need to run in cmd via the batch file. While loading the program, the second input will already be typed and the first part of that input doesn't get executed. So I need to delay atleast the first to second input altho I can't guarantee that all the other inputs perform accordingly without a delay inbetween them.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Harald
Harald am 23 Jun. 2023
Hi Jan,
I would primarily consider that an issue of the .bat-file: if it is designed to accept multiple commands via a text file, it should automatically build in those delays as needed.
If you can't modify the .bat file yourself or get its author to do so, the only alternative I see is to split the system calls and inputs.txt into multiple calls and files and insert according statements, e.g., pause or timers, in MATLAB.
Best wishes,
Harald
  2 Kommentare
Jan Knop
Jan Knop am 23 Jun. 2023
Hi Harald,
Thank you for your answer. I create the batch file for my program myself. The code looks as follows:
runfileName = 'myBatchFile.bat';
runfile = fopen(runfileName, 'w');
fprintf(runfile, 'cmd.exe < %%1');
fprintf(runfile, '\n');
fprintf(runfile, 'exit');
fprintf(runfile, '\n');
fclose(runfile);
This batch file then gets called by the system function as described in my post with the inputs defined beforehand. How would I add a delay to the batch file in that case?
Harald
Harald am 23 Jun. 2023
Hi Jan,
in that case, it might be easiest to split the .bat file into several ones and take care of the delaying in MATLAB using pause or timers.
Alternatively, this link gives some ways of delaying the execution of a .bat file:
I hope this helps. :) If it does, please kindly accept the answer.
Best wishes,
Harald

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Entering Commands finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by