How do i see the printed lines of a .exe file in Matlab?

조회 수: 3 (최근 30일)
Fabian Bengl
Fabian Bengl 2018년 9월 14일
댓글: Fabian Bengl 2018년 9월 15일
Hello, i have the following problem: i wrote an test.exe, that i want to start from matlab with the parameter 3. So i use:
system('test.exe 3')
The test.exe has the following code: ...
printf('The parameter was %d!, is it right(y/n)=?',number);
a=getchar();...
So when i start the test.exe from the windows cmd, it will first show me the text and waits for the char.
When i start the test.exe, it will show the text after the char was handed char over.
How can I solve this problem? Is it possible to start the windows cmd from matlab, so i can see the printed lines in the windows cmd window?
Thank you for Help and sorry for the bad english!
  댓글 수: 6
dpb
dpb 2018년 9월 14일
Yeah, but you STILL passed the number in the command line...that's not in the suggested form.
Just use
!test.exe
Fabian Bengl
Fabian Bengl 2018년 9월 14일
then the test.exe crashed, because no parameter was given to the file. (number)
...
printf('The parameter was %d!, is it right(y/n)=?',number);
a=getchar();
...

댓글을 달려면 로그인하십시오.

채택된 답변

Greg
Greg 2018년 9월 15일
편집: Greg 2018년 9월 15일
This isn't something MATLAB can do with system calls. And it makes sense that way, because the entire point of system or ! is that you want MATLAB to run those commands for you in the background.
To accomplish your goal, you need a command that tells Windows to force something to the foreground:
system('start test.exe 3');
Beware that with the "start" directive, the operating environment (i.e., working directory, etc.) get a lot more convoluted. Further, this will still probably be useless to you, because I'm pretty sure MATLAB continues as soon as the call is made. It won't wait for the spawned command window to be closed, so you can't use anything with whatever it is that text.exe does.
  댓글 수: 1
Fabian Bengl
Fabian Bengl 2018년 9월 15일
Thank you for your Answer. In my case this solves my problem, because the test.exe writes its output in a txt-file, which will be used in matlab. So before the txt-file will be loaded, the user will be asked, whether the exe-file finished writing.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2018년 9월 15일
You will need to use .NET for anything like this in Windows, see https://www.mathworks.com/matlabcentral/answers/414795-run-exe-with-an-input-file-and-close-upon-process-exit. You will need to figure out how you want to deal with standard input and standard output. The point is that with .NET it should be possible to talk interactively with an active process. See also https://www.mathworks.com/matlabcentral/answers/55214-reading-a-pipe-or-ouput-of-a-c-program-into-matlab#answer_315824
If you can rely upon the process always giving back the same prompts and that you do not need to make decisions or record what is sent to you for the purpose of determining what to send, then see also https://www.mathworks.com/matlabcentral/fileexchange/13851-popen-read-and-write
  댓글 수: 1
Fabian Bengl
Fabian Bengl 2018년 9월 15일
Thank you, your topics solve the basic problem i have, but this exceeds my skill level. So in my case it is easier to use
system('start test.exe 3');

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by