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
Click For Summary

Discussion Overview

The discussion revolves around automating input for an MRWE application in MATLAB, specifically focusing on how to pass input files to an executable that requires manual input. Participants explore various methods to achieve this automation, including the use of MATLAB's system command and Java's Robot class.

Discussion Character

  • Exploratory
  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant describes their inability to pass commands to an executable from MATLAB, noting that the executable prompts for an input file in a separate window.
  • Another participant shares their attempt to use the Java Robot class for automation but encounters issues with the executable running in blocking mode, preventing further code execution until manual input is provided.
  • A later reply suggests running the executable in the background to avoid blocking and provides a method to minimize the MATLAB desktop window to ensure the target application is in focus for the Robot class.
  • Another participant inquires about creating a loop to automate the input of multiple data files, seeking advice on how to dynamically change the input file name within the loop.

Areas of Agreement / Disagreement

Participants express different approaches to the problem, with no consensus on a single solution. The discussion includes multiple methods and ideas, indicating that various strategies may be explored further.

Contextual Notes

Participants mention limitations related to the blocking behavior of the executable and the need for the target application to be in focus for the Java Robot class to function correctly. The discussion does not resolve these technical challenges.

Who May Find This Useful

This discussion may be useful for MATLAB users looking to automate interactions with executables that require manual input, particularly in the context of MRWE applications.

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?
 
Physics news 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?
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 3 ·
Replies
3
Views
11K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 4 ·
Replies
4
Views
7K