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

9 views (last 30 days)
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
Ameer Hamza
Ameer Hamza on 14 May 2020
Ok. I misunderstood it to be a MATLAB function. Thanks for the information.
Joachim
Joachim on 27 May 2020
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

Community Treasure Hunt

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

Start Hunting!