MATLAB Answers

Run programm in background without using "start"

40 views (last 30 days)
MD
MD on 8 Sep 2018
Commented: MD on 10 Sep 2018
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 Comments

dpb
dpb on 9 Sep 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
MD
MD on 9 Sep 2018
I am sorry but I don't know too much about DOS. Where exactly would I need to put /wait in my string?

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 9 Sep 2018
There is no way to do that using system().
You can use .NET to start processes that run in the background.

  12 Comments

Show 9 older comments
MD
MD on 10 Sep 2018
I tried that but I got an error
Message: The Process object must have the UseShellExecute property set to false in order to redirect IO streams.
Source: System
HelpLink:
Unfortunately, there is no helplink as it indicates in the error. But apparently UseShellExecute must always be set to false.
Guillaume
Guillaume on 10 Sep 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
MD on 10 Sep 2018
I tried that as well. Unfortunately, it seems like I am out of luck because the program is still opened in the foreground. I also tried to set it to minimized but it also doesn't work.

Sign in to comment.

Sign in to answer this question.

Tags

Products


Release

R2018a