Get return values from cmd line 'live'

Hello everybody; i've got a little problem with my matlab-Code. I'm calling a external program, which converts mf4-data to *.mat files, by using the system command. Unfortunately it takes a lot of time, so I decided to use something like a waitbar, to show the progress to the user. The converting programm it self, showing a progress in percentage, if it is running directly in cmd-window. If I start it by Matlab, only at the end matlab shows me something like a summary, where all values in. I tried using the '!' operator as well as the system command. Is there a possibility, that you get the values in 'livetime'. So to say at the moment they appear in the cmd line?
Thanks a lot for helping and a have a pleasant weekend!
Greeting Dominik Sieb

Réponses (2)

dpb
dpb le 24 Nov 2017

1 vote

" Is there a possibility, that you get the values in 'livetime'."
Short answer, "no". Not from the system command route; it buffers the output internally until the detached process terminates.
You might be able to redirect the output of the process to a file instead of console and read it periodically from the Matlab session...no guarantees on whether is even possible nor how it might/might not work if can even open the file with synchronization issues, etc., ...

1 commentaire

Dominik  Sieb
Dominik Sieb le 27 Nov 2017
Thank a lot for the fast help!! Is there a possiblity to open the cmd not in background, so thats its is shown? Or is this only possible by calling a batch file via matlab?
Greetings Dominik Sieb

Connectez-vous pour commenter.

Walter Roberson
Walter Roberson le 27 Nov 2017

1 vote

In Mac and Linux, you would use the File Exchange contribution popen()
In theory it would be possible to adapt the popen code there for MS Windows by changing to _popen() but it might take a bit of fiddling.
If you look at the comments of the popen contribution, someone has posted the java equivalent there, which should be usable with Windows as well.
For MS Windows it is also possible to use .NET to start processes. See https://blogs.mathworks.com/loren/2010/12/07/using-microsoft-net-to-expand-matlab-capabilities/

Catégories

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by