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

답변 (2개)

dpb
dpb 2017년 11월 24일

1 개 추천

" 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

Dominik  Sieb
Dominik Sieb 2017년 11월 27일
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

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

Walter Roberson
Walter Roberson 2017년 11월 27일

1 개 추천

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/

카테고리

도움말 센터File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

제품

질문:

2017년 11월 24일

답변:

2017년 11월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by