close terminal window

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

Hi Steven,
"I make a program" needs some guessing about what you are doing. Perhaps you could describe this in more detail?
Titus
Steven
Steven on 7 Nov 2011
I rather mean, I call a program wich opens a terminal windows, make some calculus, but when it's finished, the terminal doesn't close
Steven
Steven on 7 Nov 2011
The point is not with the program itself, for example, just launch the cmd.exe from windows start-up menu, then how could you close it from matlab ?
I have a program that launches some xterm windows (on my Unix machine) to run other non-Matlab things in the background. Once they finish their job, the xterm automatically closes. Are you looking for a similar behavior, but with an MS-DOS command prompt?
Steven
Steven on 7 Nov 2011
It might be usefull, but I'm more looking for something simpler : I dont want to run anything in the background, I just want to close a windows.
Hi Steven,
O.K., I see. How do you call the other program (system? Using "!"?)
Titus
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

0 votes

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

0 votes

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

Steven
Steven on 7 Nov 2011
It doesn't work, I got the following :
Microsoft Windows XP [version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\DA2191\Bureau\complexe_calib_MLEp\old>Plusÿ?
ans =
0
It like if I must add something to confirm (y/n) ?
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

0 votes

Yes, if I type exit in the terminal, it close the windows.

7 Comments

Steven
Steven on 7 Nov 2011
My text file is Exit.txt, it contains only : exit
Then add that carriage return in the text file after the exit, and save the file. It should work.
Steven
Steven on 7 Nov 2011
In my text file, when I add "return" at the second line, I got :
Microsoft Windows XP [version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\DA2191\Bureau\complexe_calib_MLEp\old>exit
But the terminal is not closed. If my text file is "exit return", well I got the samething as before.
Not the literal text "return". I mean the carriage return, the "Enter" key stroke!
Steven
Steven on 7 Nov 2011
Ok I see, well It doesn't work, I got as usual:
Microsoft Windows XP [version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\DA2191\Bureau\complexe_calib_MLEp\old>exit
ans =
0
I don't understand. You still have not answered the question how your program brought up the Cmd window. See this post yourself.
http://www.mathworks.com/matlabcentral/answers/19793-using-system-to-run-an-executable-outside-of-matlab
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

0 votes

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');

Categories

Asked:

on 7 Nov 2011

Edited:

on 15 Feb 2018

Community Treasure Hunt

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

Start Hunting!