필터 지우기
필터 지우기

How to run a .bat file in background without opening command prompt?

조회 수: 77 (최근 30일)
jacopo tacconi
jacopo tacconi 2017년 12월 27일
댓글: dpb 2018년 1월 1일
Dear all, I am running a jet engine performance optimization in Matlab which has to call an external program. The external program is mainly constituted by a .bat file with the scope of solving the engine thermodynamic cycle (I have no control or access to the external program files). Matlab provides the input necessary to run the .bat and process the outputs. During the optimization, performed using fmincon, it happens that the external file get stock in an infinite loop without convergence for a set of Matlab sent input (this is normal). Therefore, I am running the external program in parallel with system(), using the & command and, when this happen, I kill the external run by means of the command "taskkill" in windows using again system() in Matlab. This is working perfectly. However, when the optimization runs, the command prompt showing the external program running keeps opening up and I can't figure out a way to prevent this to happen.
I would like to have the external program to run in background without showing all the time the black prompt, such that I can easily use the computer when the optimization runs. If the external program run directly through Matlab the prompt does not pop out automatically and the external program run is just visible on the Matlab command window. Is it possible to do the same when the same program runs in background?
I hope it is enough clear. Thank you very much in advance. Jacopo

채택된 답변

dpb
dpb 2017년 12월 27일
편집: dpb 2018년 1월 1일
Presuming Windows, try something like
cmd='yourprogram inputs'; % the command line to execute to run your model
system(['start /min' blanks(1) cmd]) % start a minimized process to run the command
This will START a new process with the window minimized and should behave the same way as your above case using system as far as running; You'll get the immediate status returned so you'll want to use a return variable form to capture it as
stat=system(['start /min' blanks(1) cmd]);
Or, you can just use the bang operator as
!['start /min' blanks(1) cmd]
instead.
I don't know for sure about **ix whether START is the right command name or not...
  댓글 수: 3
Walter Roberson
Walter Roberson 2018년 1월 1일
!['start /min' blanks(1) cmd]
will not work. The ! operator takes the remainder of the line literally, not as an expression.
dpb
dpb 2018년 1월 1일
Good point on specifics; the generic idea works to eliminate the return of the explicit system call. One of the (relatively) few places where an eval could be useful.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Nonlinear Control에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by