Running external program as batch file with delayed inputs

3 次查看(过去 30 天)
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 个评论
Rik
Rik 2023-6-23
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 2023-6-23
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.

请先登录,再进行评论。

采纳的回答

Harald
Harald 2023-6-23
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 个评论
Jan Knop
Jan Knop 2023-6-23
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 2023-6-23
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Entering Commands 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by