Automatically Entering Inputs into Program

11 ビュー (過去 30 日間)
Andrew Klingberg
Andrew Klingberg 2020 年 11 月 27 日
編集済み: Andrew Klingberg 2020 年 11 月 30 日
Hi,
I am using an old program (Program.exe) that requires you to press ENTER, then enter inputs in the following order: 'A', 'B', 'C'
commandfile = fopen('commandfile.txt','w');
fprintf(commandfile,strcat('\n', 'A', '\n', 'B', '\n', 'C', '\n');
fclose(commandfile);
system('Program.exe < commandfile.txt');
My program then runs into the error LF90.EER error # 94" (this is listed as 'Data transfer beyond end of file').
commandfile = fopen('commandfile.txt','w');
fprintf(commandfile,strcat('\n', 'A', '\n', 'B', '\n', 'C', '\n');
fclose(commandfile);
system('echo commandfile.txt | Program.exe');
My program then runs into the error "ELF90.EER error # 124" (this is listed as 'Unable to read file').
Any insight would be very much appreciated.
  1 件のコメント
Andrew Klingberg
Andrew Klingberg 2020 年 11 月 30 日
編集済み: Andrew Klingberg 2020 年 11 月 30 日
For anyone with a similar issue, I found a work around for now. Instead of sending inputs to the program via a textfile, I can enter them through keystrokes instead.
For my example, here is the code for my purpose:
h = actxserver('WScript.Shell');
h.Run('Program'); %Invokes Program.exe
pause(3); %Waits for Program to load.
h.AppActivate('Program'); %Brings Program to focus
h.SendKeys('~'); %Sends return
pause(5/100); %Waits briefly for program
h.SendKeys('A~'); %Sends A and return
pause(5/100); %Waits briefly for program
h.SendKeys('B~'); %Sends B and return
pause(5/100); %Waits briefly for program
h.SendKeys('C~'); %Sends C and return
pause(5/100); %Waits briefly for program
h.SendKeys('%{F4}'); % closes Program using Alt+F4

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by