Running .exe file from MTLAB using system() and Wait until the program closes

5 次查看(过去 30 天)
Hi everyone,
I use system to run my executable file:
system('myfile.exe')
How to determine that the program was closed? I want MATLAB to run the next line after closing the execution program. Thanks

回答(2 个)

dpb
dpb 2017-9-25
>> help system
system Execute system command and return result.
[status,result] = system('command') calls upon the operating system to
execute the given command. The resulting status and standard output
are returned.
...
continue reading for further details...
  1 个评论
abbas jalilian
abbas jalilian 2017-10-17
Thank you for your answer But my problem has not yet been resolved I've written a program with Processing and when I run it, MATLAB instantly runs the next lines.

请先登录,再进行评论。


Joao
Joao 2017-9-28
I have a similar issue, but in my case the variables status / result are not updated when the executable finishes. It seems to me that these variables are in place to indicate the status of the call to the system function not its output! Any further ideas would be much appreciated!
  2 个评论
Steven Lord
Steven Lord 2017-9-28
You should probably post this as a separate question, not as an answer on another question. If you do post as a separate question please show the exact line of code you use to call your executable, state what you observed when you executed that line of code, and explain what you expected that line of code to do (referencing parts of that code).
dpb
dpb 2017-9-28
The status is command status; whether it was/was not executed w/o error. The result returned is dependent upon the executed command using stdout for whatever output it returns. Also if you use the trailing ampersand '&' when submitting the command the result output is not updated and status is the status on launching the background session, not on completion.
It can be illustrated to work with command that is known to behave using stdin/stdout; not every console program you may try to execute follows those rules--
>> [stat,res]=system('cd') % simple command w/ known output...
stat =
0
res =
C:\ML_R2014b\work
>> [stat,res]=system('cd:') % oopsies, made a typo...
stat =
1
res =
The filename, directory name, or volume label syntax is incorrect.
>>

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by