How to run a .bat file in background without opening command prompt?
58 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
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
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 Center 和 File Exchange 中查找有关 Thermodynamics and Heat Transfer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!