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

50 vues (au cours des 30 derniers jours)
jacopo tacconi
jacopo tacconi le 27 Déc 2017
Commenté : dpb le 1 Jan 2018
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

Réponse acceptée

dpb
dpb le 27 Déc 2017
Modifié(e) : dpb le 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 commentaires
Walter Roberson
Walter Roberson le 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 le 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Thermodynamics and Heat Transfer dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by