Start-Process * -Passthru does not return the correct PID

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 17:05:10

问题


$app = Start-Process notepad -Passthru
Wait-Process $app.Id

This method returns the wrong PID. I try to stop the process right after the process is started using the PID and get the following error:

10424
Stop-Process : Cannot find a process with the process identifier 10424.
At F:{{Redacted path}}\Dev_WAS_V85_All_Open.ps1:8 char:13
+ Stop-Process <<<< $app.Id
     + CategoryInfo          : ObjectNotFound: (10424:Int32) [Stop-Process], ProcessCommandException
     + FullyQualifiedErrorId : NoProcessFoundForGivenId,Microsoft.PowerShell.Commands.StopProcessCommand

Added code below.

$pid_id_array = @()
$pid_id_array_index = 0
Set-Location F:\{{Redacted path}}\scripts\windows\BlueZone
Start-Process _clip.bat
$app = Start-Process {{Redacted part of the file name}}_server1.bat -passthru
Wait-Process $app.Id
write-host $app.Id
Stop-Process $app.Id
$app = Start-Process {{Redacted part of the file name}}_server1_FTP.bat -passthru
Wait-Process $app.Id
write-host $app.Id
Stop-Process $app.Id
$app = Start-Process {{Redacted part of the file name}}_server1_DMgr_FTP.bat -passthru
Wait-Process $app.Id
write-host $app.Id
Stop-Process $app.Id
$app = Start-Process {{Redacted part of the file name}}_server1_ISC.url -passthru
Wait-Process $app.Id
write-host $app.Id
Stop-Process $app.Id
$app = Start-Process {{Redacted part of the file name}}_CLI_strings.docx -passthru
Wait-Process $app.Id
write-host $app.Id
Stop-Process $app.Id
$app = Start-Process {{Redacted part of the file name}}_DMgr_CLI_strings.docx -passthru
Wait-Process $app.Id
write-host $app.Id
Stop-Process $app.Id
exit

来源:https://stackoverflow.com/questions/45149718/start-process-passthru-does-not-return-the-correct-pid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!