Start-Process * -Passthru不返回正确的PID

时间:2017-07-17 16:54:27

标签: powershell windows-7-x64

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

此方法返回错误的PID。我尝试在使用PID启动进程后立即停止进程并获得以下错误:

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

在下面添加了代码。

$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

0 个答案:

没有答案