Running external program as batch file with delayed inputs

3 views (last 30 days)
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 Comments
Rik
Rik on 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 on 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.

Sign in to comment.

Accepted Answer

Harald
Harald on 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 Comments
Jan Knop
Jan Knop on 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 on 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

Sign in to comment.

More Answers (0)

Categories

Find more on Entering Commands in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!