Using start-process and -wait in Powershell

I am new to Powershell and don't have much programming experience, just trying to use it to package software. Anyway, I found out about the start-process command with the -Wait parameter, and it works fine for most things. However, I noticed that he not only waits for the process you specified, but also expects any subprocesses even after the main process no longer works. This is usually good, but I have a strange situation. I am running a complex Oracle batch package with the start of the process. Ultimately, the batch file launches the setup.exe file, which I really want to wait for, but other processes also appear, which never stops. Therefore, if I use the -wait option, the script never stops even after setup.exe no longer works. The closest I found is:

saps -FilePath "Path\config.bat" -ArgumentList "arguments" Start-Sleep -s 10 Wait-Process -Name "setup" 

This works, but I think it would be better not to use the timeout command. Any ideas?

+5
source share
1 answer

you can easily use this command:

 $myprocss = Start-Process "powershell" -PassThru $myprocss.WaitForExit() 

this command will continue at the end of the process.

+11
source

Source: https://habr.com/ru/post/1259095/


All Articles