Run programm in background without using "start"
Mostrar comentarios más antiguos
Hello everyone!
My question is related to this one. I am trying to run my program in the background using the system command. However, if I understood correctly, when I add "start /b" to the command it does not wait for the other program to finish before continuing with the other operations.
Here is the input line for system that starts the program and waits for it to finish, however, opens in the foreground:
"energyPLAN.exe" -i "energyPlan Data\Data\Portugal_2050_tmp.txt" -ascii "Outputs\Portugal_2050_out"
"energyPLAN.exe" is the program, "energyPlan Data\Data\Portugal_2050_tmp.txt" is the input file and "Outputs\Portugal_2050_out" the output file.
This is the line that starts the program in the background, but does not wait for energyPLAN.exe to finish:
start /b "title" "energyPLAN.exe" -i "energyPlan Data\Data\Portugal_2050_tmp.txt" -ascii "Outputs\Portugal_2050_out"
What is the correct input that starts the program in the background but waits for it to finish?
Thanks in advance!
2 comentarios
dpb
el 9 de Sept. de 2018
What that does is shell to the command interpreter which then starts yet another session in which the executable is executed (without a console owing to /B) while the first shell exits.
Try /WAIT
Respuestas (1)
Walter Roberson
el 9 de Sept. de 2018
0 votos
There is no way to do that using system().
You can use .NET to start processes that run in the background.
12 comentarios
Walter Roberson
el 9 de Sept. de 2018
MD
el 9 de Sept. de 2018
Walter Roberson
el 9 de Sept. de 2018
Unfortunately it is not clear to me how to configure multiple arguments. Perhaps you would just configure
proc.StartInfo.Arguments = '-i "energyPlan Data\Data\Portugal_2050_tmp.txt" -ascii "Outputs\Portugal_2050_out"'
MD
el 9 de Sept. de 2018
Walter Roberson
el 9 de Sept. de 2018
... for some definition of "background"
MD
el 10 de Sept. de 2018
Sean de Wolski
el 10 de Sept. de 2018
The enumeration of ProcessWindowStyle.Hidden appears to be 1:
So something like this:
proc.StartInfo.WindowStyle = uint32(1)
Guillaume
el 10 de Sept. de 2018
As documented, "If you set the WindowStyle to ProcessWindowStyle.Hidden, UseShellExecute must be set to true".
I don't know which gets ignored when the two are not compatible. What happens if you leave UseShellExecute to its default true?
MD
el 10 de Sept. de 2018
Guillaume
el 10 de Sept. de 2018
Don't redirect the standard output and input then! If you do need to redirect the standard output or input then I think you're out of luck.
MD
el 10 de Sept. de 2018
Categorías
Más información sobre Get Started with Microsoft .NET en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
