.exe file user input promt doesn't print in Matlab command window

3 views (last 30 days)
Hello, I am in need of some help. I am trying to call this C++.exefile through Matlab using system('command'). When I call it nothing comes up. But I when I put in the user input and press enter twice it prints the results tO me. And then call my goodbye function without my input. The file works great the windows command window but only on Matlab command it does that. Is there anything I can do to fix that? I do not wish to use mex to do that. Please help
  1 Comment
James Tursa
James Tursa on 29 Jan 2013
When you do this you are using the MATLAB command window as a CONSOLE. Unfortunately, this does not work properly for screen I/O as you have discovered (things get buffered, etc). I don't know why this doesn't work correctly but it has been that way for years. I don't know of any fix, so you are stuck with workarounds as listed below.

Sign in to comment.

Answers (1)

Jason Ross
Jason Ross on 29 Jan 2013
Can you recompile the .exe file to take command line arguments rather than relying upon interactive input? e.g.
myexe.exe -flag1 value1 -flag2 value2
Could you recompile it to take an input file? e.g.
myexe.exe c:\temp\inputs.txt
Does command line redirection to pass an input file via the system command work? Reference : http://technet.microsoft.com/en-us/library/bb490982.aspx e.g.
myexe.exe < c:\temp\inputs.txt
You should be able to see if the "<" operator works outside of MATLAB. The other approaches of processing arguments and parsing input files require access to the source code for the .exe to build it in -- which you may or may not have access to. If the "<" operator works, you can mimic the command entry for your .exe in MATLAB (plus you could do error checking on the inputs), generate the text file, and then build the command line to pass in the file.
Jason Ross
Jason Ross on 29 Jan 2013
You can also try the following:
system('cmd /c <put the path to your exe here>');
system('call <put the path to your exe here>');

Sign in to comment.


Find more on Entering Commands in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!