MATLAB Answers

close terminal window

19 views (last 30 days)
Steven
Steven on 7 Nov 2011
Edited: Martijn van Sluis on 15 Feb 2018
Hi,
I make a program wich open the terminal window(C:\WINDOWS\system32\cmd.exe) at each time it's fired. I use it in a loop, so I got many useless terminal windows.
My question is : how to close a terminal window from matlab.
Greetings, Steven
  7 Comments
Steven
Steven on 7 Nov 2011
I know it uses java socket, but I can't tell you really more for now, but go ahead with some ideas using system, I'm interested.

Sign in to comment.

Accepted Answer

Steven
Steven on 7 Nov 2011
I got it, I thought matlab could do it by itself, but instead I modify the batch file of the program.

More Answers (3)

Fangjun Jiang
Fangjun Jiang on 7 Nov 2011
Assume you run your MATLAB code as system('MyProgram.exe') and it brought up that ugly black window but never exits, you can do this:
system('MyProgram.exe < Exit.txt'), where Exit.txt is a text file you created ahead of time. The text file contains one line, which is 'exit' without both the single quotes.
  2 Comments
Fangjun Jiang
Fangjun Jiang on 7 Nov 2011
So, you are using system(), right? Maybe I should emphasize that the text file should contain the text "exit" and then a carriage return. As if you are doing it manually. In one of the open command window, if you type exit and then return, it will close the window, right?

Sign in to comment.


Steven
Steven on 7 Nov 2011
Yes, if I type exit in the terminal, it close the windows.
  7 Comments
Fangjun Jiang
Fangjun Jiang on 20 Dec 2011
It should be the less than sign "<", not the greater than sign ">"!!!

Sign in to comment.


Martijn van Sluis
Martijn van Sluis on 15 Feb 2018
Edited: Martijn van Sluis on 15 Feb 2018
Perhaps not so elegant, but if you incorporate the following it works just fine:
keyInject('C:\Windows\system32\cmd.exe','exit','C:\Windows\system32\cmd.exe');
keyInject('C:\Windows\system32\cmd.exe','\r','C:\Windows\system32\cmd.exe');

Community Treasure Hunt

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

Start Hunting!