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

2 visualizaciones (últimos 30 días)
Mini Me
Mini Me el 29 de En. de 2013
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 comentario
James Tursa
James Tursa el 29 de En. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Jason Ross
Jason Ross el 29 de En. de 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.
  6 comentarios
Jason Ross
Jason Ross el 29 de En. de 2013
Yes. I get that your .exe requests interactive keyboard input. I've written these kind of programs in the past, myself. I'm trying to provide you with an alternative means of providing input to your .exe file to let you get on with solving your overall problem.
Can you please do the following as an experiment?
1. Create a text file in your favorite editor. On each line, put the inputs you would give to the .exe file. It will likely look like
N
F
S
N
2. Save that file somewhere. Call it "myinput.txt"
3. On the Windows command prompt, type
myexe.exe < myinput.txt
Note that you might need to provide paths to each file if they don't share the same directory.
4. See if the program runs in the same manner as if you hit "N S F N" as responses to the keyboard prompts. That's what the "<" operator does on the command prompt "Reads the command input from a file, instead of reading input from the keyboard." (reference: http://technet.microsoft.com/en-us/library/bb490982.aspx)
Other possibilities:
  • Add in some line endings after your prompts in your .exe file (I'm assuming you have the source code) to see if that will make the prompt appear in MATLAB.
  • It's really far easier to add in some command line handling of arguments (if you have the ability to do so) in your .exe file, then ask the questions in MATLAB and pass them all as one command. This makes the control flow a lot easier to deal with since you are only running one command, and there is an affordance to capture the output and exit status on the left hand side of the system() command if you want that. If you are doing this kind of thing a lot, it's far easier to maintain and troubleshoot than trying approaches like input files.
Jason Ross
Jason Ross el 29 de En. de 2013
You can also try the following:
system('cmd /c <put the path to your exe here>');
or
system('call <put the path to your exe here>');

Iniciar sesión para comentar.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by