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

48 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

dpb
dpb am 27 Dez. 2017
Bearbeitet: dpb am 1 Jan. 2018
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 Kommentare
Walter Roberson
Walter Roberson am 1 Jan. 2018
!['start /min' blanks(1) cmd]
will not work. The ! operator takes the remainder of the line literally, not as an expression.
dpb
dpb am 1 Jan. 2018
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Thermodynamics and Heat Transfer finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by