Automatically entering inputs into executable code at prompt

72 ビュー (過去 30 日間)
Bob Thompson
Bob Thompson 2018 年 2 月 8 日
コメント済み: Chien-Han Su 2020 年 8 月 22 日
I have an old executable code, say run.exe, which asks for user inputs. I would like to create a script which automatically runs the executable and enters the user inputs. I have figured out how to run the code, but I am not sure how to enter the inputs at the prompt in an automated fashion.
execute = '!run.exe'
eval(execute) % This runs the executable
% Executable returns:
Enter input value a:
I do not have access to the coding for the executable, and I have not seen it, so I do not know how to recreate it. Is it possible to have automatic entries for this type of situation?

回答 (1 件)

Bob Thompson
Bob Thompson 2018 年 2 月 13 日
Ok, I figured out how to do this. Basically instead of entering the inputs as individual commands the inputs are entered into a text file.
commandfile = fopen('commandfile.txt','w');
fprintf(commandfile,'Enter inputs to read in executable here');
fclose(commandfile);
system('executable.exe < commandfile.txt'); % I used the system command here, rather than evaling '!'. I believe they both would work, but I decided to stick with system from another user.
By using the actually command prompt command of 'executable.exe < commandfile.txt' command prompt knows to run the executable and read the command input text at the same time, allowing for commands to be entered into the executable.
  1 件のコメント
Chien-Han Su
Chien-Han Su 2020 年 8 月 22 日
This works for me (on MATLAB 2020a under Ubuntu 20.04 LTS)! Thank you!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by