Continue matlab while a dos/system command is executed / close dos window

I have to use a dos-Programm where I don't have the source code. This programm controlls some measurement device via ftp.
To start the programm I call it by
answer = dos(['my_programm.exe', optionsstring])
The programm produces periodic output that is print to the matlab command window.
It runns until it is stopped by calling another exe (which writes something into a file that is read by the first...)
answer = dos(['my_end_programm.exe', optionsstring])
This works fine, if the two dos-comands are executed in a callback of a gui in Matlab2014a! Execution of 'my_programm.exe' does not block matlab. The gui stays aktive and I can press some button that triggers the 'end'-command.
However in matlab 2019b this does not work any more. The dos-command seems to block matlab. matlab waits until 'my_programm.exe' ends - which does not happen.
Also in 2014a when called from a scipt - no gui-callback - matlab gets blocked by the dos command.
Is there a way around this? Preferable in matlab 2019b or 2020?
As a workaround I use the option '&' in 2014:
answer = dos(['my_programm.exe', optionsstring, ' &'])
This opens a dos console window. The output of 'my_programm' gets there - which is aceptabel - but the window stays open. Since I call 'my_programm.exe' a couple of times this gets messy.
How can i close the dos console window?
Thank you for any help!

6 Comments

Try to use system() function instead of dos().
@Ameer, I have alway thought those were equivalent if run on a Windows machine. I can't find anything in the doc suggesting otherwise. Have you come across a difference?
No, I didn't found any difference. That was just a guess. The least it did is to bring this question up in recent activity so that someone who knows this stuff can answer xD
Btw, can you point to the documentation page for the start() you mentioned in your answer? There are several start() functions for different classes, and I couldn't find the one related to running external programs from MATLAB.
The start I meant is actually not part of Matlab, but Windows. I don't know if it is a copy the actual documentation, but this page looks like it explains that command.
Ok. I misunderstood it to be a MATLAB function. Thanks for the information.
thank you for your comments. 'system' and 'dos' seems to be the same.
'start' might be the solution for my task.
dos(['demo.exe', ' 4', ' &']) --> opens the cmd window, matlab countinues, cmd stays open
dos(['start demo.exe', ' 4']) --> opens the cmd window, matlab continues, cmd closes after exe finished
thank you for the suggestion!
But why does 'dos' behave differtly if called by a GUI-callback or script in Matlab 2014/2019???

Sign in to comment.

 Accepted Answer

Rik
Rik on 14 May 2020
Edited: Rik on 14 May 2020
Try the start command. It will detach and run, so that might run your starter function without opening a new cmd window.
Another possibility would be to have an executable created with bat2exe (google is your friend). Last time I used that it had the option of running without a visible window. That way you can run that executable with system('start wrapperbat.exe').

More Answers (0)

Products

Release

R2019b

Asked:

on 14 May 2020

Commented:

on 27 May 2020

Community Treasure Hunt

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

Start Hunting!