close terminal window

조회 수: 10 (최근 30일)
Steven
Steven 2011년 11월 7일
편집: Martijn van Sluis 2018년 2월 15일
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
Titus Edelhofer
Titus Edelhofer 2011년 11월 7일
Hi Steven,
O.K., I see. How do you call the other program (system? Using "!"?)
Titus
Steven
Steven 2011년 11월 7일
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.

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

채택된 답변

Steven
Steven 2011년 11월 7일
I got it, I thought matlab could do it by itself, but instead I modify the batch file of the program.

추가 답변 (3개)

Fangjun Jiang
Fangjun Jiang 2011년 11월 7일
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
Steven
Steven 2011년 11월 7일
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) ?
Fangjun Jiang
Fangjun Jiang 2011년 11월 7일
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
Steven 2011년 11월 7일
Yes, if I type exit in the terminal, it close the windows.
  댓글 수: 7
Fangjun Jiang
Fangjun Jiang 2011년 11월 7일
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
Fangjun Jiang 2011년 12월 20일
It should be the less than sign "<", not the greater than sign ">"!!!

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


Martijn van Sluis
Martijn van Sluis 2018년 2월 15일
편집: Martijn van Sluis 2018년 2월 15일
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');

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by