简体   繁体   English

在 Powershell 中使用 start-process 和 -wait 命令

[英]Using start-process and -wait command in Powershell

I am new to Powershell and don't have much of a programming background, just trying to use it for software packaging.我是 Powershell 的新手,没有太多的编程背景,只是想用它来进行软件打包。 Anyway, I found out about the start-process command with the -Wait parameter, and it works great for most things.不管怎样,我发现了带有 -Wait 参数的 start-process 命令,它对大多数事情都很有效。 What I noticed though is that not only does it wait for the process you specify, it waits for any sub processes, even after the main process is no longer running.但是我注意到它不仅等待您指定的进程,它还等待任何子进程,即使在主进程不再运行之后。 Usually this is good, but I have a weird situation.通常这很好,但我有一个奇怪的情况。 I am running a complex Oracle batch file with start-process.我正在使用启动进程运行一个复杂的 Oracle 批处理文件。 The batch file eventually runs setup.exe which is what I really want to wait for, but other processes spawn too that never stop.批处理文件最终会运行 setup.exe,这是我真正想要等待的,但其他进程也不会停止。 So if I use the -wait parameter, the script never stops even after setup.exe is no longer running.因此,如果我使用 -wait 参数,即使 setup.exe 不再运行,脚本也不会停止。 The closest I've found is using this:我发现的最接近的是使用这个:

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

This works, but I would think there'd be a better way without having to use a timeout command.这有效,但我认为有更好的方法而不必使用超时命令。 Any ideas?有什么想法吗?

you can use this command easy :您可以轻松使用此命令:

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

this command will continue when process end .该命令将在进程结束时继续。

使用Start-Process ,有一个等待选项:

Start-Process -Wait -FilePath "do_things.exe" -ArgumentList "argument another_argument"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM