How Can I Automate Input for an MRWE Application in MATLAB?

  • Context: MATLAB 
  • Thread starter Thread starter natejensen
  • Start date Start date
  • Tags Tags
    Matlab Running
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 13K views
natejensen
Messages
7
Reaction score
0
I have already referred to this posting:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/241352
so I know the basics of running an executable from Matlab and inputing a file for it to run.

My problem is that because of the way my executable was written, I can only run the executable and not pass commands to it from Matlab. I have tried passing commands to the executable from the command window and that does not work either.

This works fine:
system('C:\...\executable.exe')
And the only thing any of these:
system(['C:\...\executable.exe<' input_file])
system(['C:\...\executable.exe ' input_file])
system(['C:\...\executable.exe <' input_file])
do is just run the executable.

When the executable is run, a "dos like" window pops up with a prompt to input the input file. From there I can manually enter in the input file, but that isn't really all that helpful if I want to run it 1000 times.

This "dos like" window is an MRWE Application Framework. I tried searching "matlab mrwe," but just came up with a bunch of dead links. It doesn't seem like absoft is supported by Matlab, but I just need to input a few lines of text. It shouldn't be too hard right?
 
on Phys.org
Alright so I've been messing with that Java Robot Class stuff, and found this:
http://undocumentedmatlab.com/blog/gui-automation-robot/

I tried following their example but it's not working yet. This is what my code looks like now:

system('C:\...\executable.exe')
robot = java.awt.Robot;
robot.keyPress (java.awt.event.KeyEvent.VK_V);
robot.keyRelease (java.awt.event.KeyEvent.VK_V);
robot.keyPress (java.awt.event.KeyEvent.VK_E);
robot.keyRelease (java.awt.event.KeyEvent.VK_E);
robot.keyPress (java.awt.event.KeyEvent.VK_R);
robot.keyRelease (java.awt.event.KeyEvent.VK_R);
robot.keyPress (java.awt.event.KeyEvent.VK_ENTER);
robot.keyRelease (java.awt.event.KeyEvent.VK_ENTER);

When I run this, the code gets stuck on the first line. After the system command, the executable asks for an input file. It doesn't matter if I click on any other window (Matlab, the executable, my computer, whatever...) the code will not go to the second line until I either manually type in an input file, or close the executable.

I also tried switching the first two lines, but to no avail.

Any ideas?
 
I know that I'm the only replying in this thread, so I don't know if anybody cares, but here is the answer.

This is because you run your executable in blocking mode. Instead, run your executable in the background:
system('C:\...\executable.exe &')

Note that the robot key-press require the target application to be in focus. You can do this by minimizing the Matlab desktop window:
com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame.setMinimized(true);

Yair Altman
http://UndocumentedMatlab.com
 
Great work. I have ten data input files named (data1,data2,...,data10), Is it possible to make loop that consider the new name of input file??. In other way suppose we have something like :

for i =1:10
system('abcd.exe &');
robot = java.awt.Robot;
robot.keyPress (java.awt.event.KeyEvent.VK_D);
robot.keyRelease (java.awt.event.KeyEvent.VK_D);
robot.keyPress (java.awt.event.KeyEvent.VK_A);
robot.keyRelease (java.awt.event.KeyEvent.VK_A);
robot.keyPress (java.awt.event.KeyEvent.VK_T);
robot.keyRelease (java.awt.event.KeyEvent.VK_T);
robot.keyPress (java.awt.event.KeyEvent.VK_A);
robot.keyRelease (java.awt.event.KeyEvent.VK_A);
robot.keyPress (java.awt.event.KeyEvent.VK_i); -------------> change i to be 1,2,3,...10
robot.keyRelease (java.awt.event.KeyEvent.VK_i);-------------> change i to be 1,2,3,...10
robot.keyPress (java.awt.event.KeyEvent.VK_ENTER);
robot.keyRelease (java.awt.event.KeyEvent.VK_ENTER);
end
how to pass the file name as a variable?