Feedback from Command/DOS window

조회 수: 3 (최근 30일)
Reto Christen
Reto Christen 2019년 5월 9일
댓글: Reto Christen 2019년 5월 9일
Hello,
I have some problems while working with an external command window.
In Matlab I have to run an executable which will connect to a server. Setting up this connection takes roughly 10 to 20 seconds and the port number of the connection is then written into this command window. I am now looking for a possibility to read out this port number, since it is vital for my next steps in Matlab.
I tried to run the command
[status,cmdout] = system('mycommand.exe &');
However, since the server first has to connect, cmdout is just an empty string. I there a possibility to 'rerun' the command to get the correct cmdout-value?
Right now I am using a Matlab Input-Dialog to get the port number manually. It works but a nicer automated solution would be prefered.
I would greatly appreciate your help.
  댓글 수: 2
David Wilson
David Wilson 2019년 5월 9일
You could try the dos command, without the trailing ampersand. That way Matlab might wait, and not try to do it in the background.
Reto Christen
Reto Christen 2019년 5월 9일
Thanks for your reply.
Unfortunately, mycommand.exe not only opens the connection but it keeps it open while using the server. For this reason, mycommand.exe must be running in the background (I should have written this more clearly, sorry). Hence, an ampersand is needed.
Using the dos command actually returned the wanted string, but well, my application cannot continue and everything is 'blocked'.

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

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2019년 5월 9일
I don't know if this old trick could work. Try system('mycommand.exe & >output.txt'). Hope all the output would be re-directed to the specified text file. It might take a while for your mycommand.exe to finish. But once the output is saved in a text file, your next run could read it and get the info.
  댓글 수: 1
Reto Christen
Reto Christen 2019년 5월 9일
Thanks for your reply.
This would be the perfect command for me. Unfortunately, I get the error message The syntax of the command is incorrect, but only with the ampersand. system('mycommand.exe >output.txt') works as excpected, but again the same problem with the 'blocked' application.

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

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by