Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
I need some help with running a .exe from Matlab

Subject: I need some help with running a .exe from Matlab

From: Nathan Jensen

Date: 3 Mar, 2011 15:58:04

Message: 1 of 10

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?

Subject: I need some help with running a .exe from Matlab

From: Think blue, count two.

Date: 3 Mar, 2011 16:13:55

Message: 2 of 10

On 03/03/11 9:58 AM, Nathan Jensen wrote:
> 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?

Java Robot class

Subject: I need some help with running a .exe from Matlab

From: Nathan Jensen

Date: 3 Mar, 2011 16:35:18

Message: 3 of 10

> Java Robot class

Awesome thanks! I haven't done a lot of searching yet, but could you point me in the direction of a tutorial, or a few examples?

Thanks

Subject: I need some help with running a .exe from Matlab

From: Nathan Jensen

Date: 3 Mar, 2011 18:20:22

Message: 4 of 10

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?

Subject: I need some help with running a .exe from Matlab

From: TideMan

Date: 3 Mar, 2011 18:54:10

Message: 5 of 10

On Mar 4, 4:58 am, "Nathan Jensen" <jensen.pi...@gmail.com> wrote:
> 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?

What does your string input_file contain?
Does it contain the name of the file that the program is asking you to
input?
If so, then it won't work.
input_file needs to be the name of a file containing the name of the
file that must be input.
Do you follow me?

Subject: I need some help with running a .exe from Matlab

From: Nathan Jensen

Date: 3 Mar, 2011 19:29:25

Message: 6 of 10

> What does your string input_file contain?
> Does it contain the name of the file that the program is asking you to
> input?
> If so, then it won't work.
> input_file needs to be the name of a file containing the name of the
> file that must be input.
> Do you follow me?

Yes, I understand, and yes that is what I am doing. The problem is that when I run:
system(['C:\...\executable.exe<' input_file])
it stops executing the system command after the executable is executed. I don't know why, but it completely ignores anything after the " system(['C:\...\executable.exe ". It is as if the " '<' input_file]) " part of the " system(['C:\...\executable.exe<' input_file]) " is not even there.

Then it gets annoying because, like I said in the previous post, the Matlab script stops running and will not finish until I have either closed the executable or entered an input file.

I was hoping that even if I could not use system to run an executable with an input file, I could use something like java robot, but if Matlab won't even go to the line after the system command, I'm not sure what I am going to do.

Thank you though for your suggestions. Hopefully somebody can figure it out.

Subject: I need some help with running a .exe from Matlab

From: TideMan

Date: 3 Mar, 2011 20:20:38

Message: 7 of 10

On Mar 4, 8:29 am, "Nathan Jensen" <jensen.pi...@gmail.com> wrote:
> > What does your string input_file contain?
> > Does it contain the name of the file that the program is asking you to
> > input?
> > If so, then it won't work.
> > input_file needs to be the name of a file containing the name of the
> > file that must be input.
> > Do you follow me?
>
> Yes, I understand, and yes that is what I am doing.  The problem is that when I run:
> system(['C:\...\executable.exe<' input_file])
> it stops executing the system command after the executable is executed.  I don't know why, but it completely ignores anything after the " system(['C:\...\executable.exe ".  It is as if the " '<' input_file]) " part of the " system(['C:\...\executable.exe<' input_file]) " is not even there.
>
> Then it gets annoying because, like I said in the previous post, the Matlab script stops running and will not finish until I have either closed the executable or entered an input file.
>
> I was hoping that even if I could not use system to run an executable with an input file, I could use something like java robot, but if Matlab won't even go to the line after the system command, I'm not sure what I am going to do.
>
> Thank you though for your suggestions.  Hopefully somebody can figure it out.

So, what happens if you open a DOS window and type in the command:
C:\...\executable.exe < input.run
where input.run contains a single line containing the name of the
input file that you would enter into the "dos like" window?

If it still does not work, then your problem is with the .exe, not
Matlab. Perhaps you can get a command line version of it?

I run many, many such programs from Matlab.
Some of them are my own .exe files from Fortran, and some are DOS
versions of well-known programs such as WinRAR, cURL, GrADSDODS, etc,
etc.
I've never had the problem you describe.

Subject: I need some help with running a .exe from Matlab

From: Yair Altman

Date: 3 Mar, 2011 20:36:05

Message: 8 of 10

"Nathan Jensen" <jensen.pikes@gmail.com> wrote in message <ikom56$1n4$1@fred.mathworks.com>...
> 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;
[snip]
>
> 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?


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

Subject: I need some help with running a .exe from Matlab

From: Nathan Jensen

Date: 3 Mar, 2011 20:37:20

Message: 9 of 10

> So, what happens if you open a DOS window and type in the command:
> C:\...\executable.exe < input.run
> where input.run contains a single line containing the name of the
> input file that you would enter into the "dos like" window?
>
> If it still does not work, then your problem is with the .exe, not
> Matlab. Perhaps you can get a command line version of it?
>
> I run many, many such programs from Matlab.
> Some of them are my own .exe files from Fortran, and some are DOS
> versions of well-known programs such as WinRAR, cURL, GrADSDODS, etc,
> etc.
> I've never had the problem you describe.

The same thing happens, nothing. I also believe that problem resides in the .exe. I asked the guy who gave it to me to recompile it so that it would run in a true dos window, able to accept commands from a command prompt, but he didn't seem too thrilled to do so. I'll ask again to see if I can get the source, but I'm pretty sure that my security clearance isn't high enough to do that yet.

Thank you for your help TideMan, I appreciate your expertise. I understand that this problem is not easy to solve, especially when I do not have the source. I was just hoping that there might be a work around.

Subject: I need some help with running a .exe from Matlab

From: Nathan Jensen

Date: 3 Mar, 2011 20:51:20

Message: 10 of 10

> 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

You are the man Yair Altman!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us