Automatically Entering Inputs into Program

조회 수: 14 (최근 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 CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by