close terminal window
Ältere Kommentare anzeigen
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 Kommentare
Titus Edelhofer
am 7 Nov. 2011
Hi Steven,
"I make a program" needs some guessing about what you are doing. Perhaps you could describe this in more detail?
Titus
Steven
am 7 Nov. 2011
Steven
am 7 Nov. 2011
Dr. Seis
am 7 Nov. 2011
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
am 7 Nov. 2011
Titus Edelhofer
am 7 Nov. 2011
Hi Steven,
O.K., I see. How do you call the other program (system? Using "!"?)
Titus
Steven
am 7 Nov. 2011
Akzeptierte Antwort
Weitere Antworten (3)
Fangjun Jiang
am 7 Nov. 2011
0 Stimmen
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 Kommentare
Steven
am 7 Nov. 2011
Fangjun Jiang
am 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?
Steven
am 7 Nov. 2011
0 Stimmen
7 Kommentare
Steven
am 7 Nov. 2011
Fangjun Jiang
am 7 Nov. 2011
Then add that carriage return in the text file after the exit, and save the file. It should work.
Steven
am 7 Nov. 2011
Fangjun Jiang
am 7 Nov. 2011
Not the literal text "return". I mean the carriage return, the "Enter" key stroke!
Steven
am 7 Nov. 2011
Fangjun Jiang
am 7 Nov. 2011
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
Fangjun Jiang
am 20 Dez. 2011
It should be the less than sign "<", not the greater than sign ">"!!!
Martijn van Sluis
am 15 Feb. 2018
Bearbeitet: Martijn van Sluis
am 15 Feb. 2018
0 Stimmen
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');
Kategorien
Mehr zu Entering Commands finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!