Feedback from Command/DOS window

2 views (last 30 days)
Reto Christen
Reto Christen on 9 May 2019
Commented: Reto Christen on 9 May 2019
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 Comments
David Wilson
David Wilson on 9 May 2019
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 on 9 May 2019
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'.

Sign in to comment.

Answers (1)

Fangjun Jiang
Fangjun Jiang on 9 May 2019
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 Comment
Reto Christen
Reto Christen on 9 May 2019
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.

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!