如何使powershell等待exe安装?

如何使powershell等待exe安装?,powershell,Powershell,因此,我已经阅读了与这个问题相关的每一个答案,但它们似乎都不起作用 我在剧本中有这样几句话: $exe = ".\wls1033_oepe111150_win32.exe" $AllArgs = @('-mode=silent', '-silent_xml=silent_install.xml', '-log=wls_install.log"') $check = Start-Process $exe $AllArgs -Wait -Verb runAs $check.WaitForExit()

因此,我已经阅读了与这个问题相关的每一个答案,但它们似乎都不起作用

我在剧本中有这样几句话:

$exe = ".\wls1033_oepe111150_win32.exe"
$AllArgs = @('-mode=silent', '-silent_xml=silent_install.xml', '-log=wls_install.log"')
$check = Start-Process $exe $AllArgs -Wait -Verb runAs
$check.WaitForExit()
运行此操作后,我会对已安装的文件进行正则表达式检查,以替换某些特定字符串,但无论我尝试执行什么操作,它都会在程序安装时继续运行正则表达式检查


如何使下一行在安装完exe之前不执行?我还尝试了将管道输出为Null,但没有成功。

我创建了一个测试可执行文件,它执行以下操作

    Console.WriteLine("In Exe start" + System.DateTime.Now);
    System.Threading.Thread.Sleep(5000);
    Console.WriteLine("In Exe end" + System.DateTime.Now);
然后编写了这个powershell脚本,该脚本按预期等待exe完成运行,然后输出文本“结束ps1”和时间

push-location "C:\SRC\PowerShell-Wait-For-Exe\bin\Debug";
$exe = "PowerShell-Wait-For-Exe.exe"  
$proc = (Start-Process $exe -PassThru)
$proc | Wait-Process

Write-Host "end of ps1" + (Get-Date).DateTime
下面的powershell也会正确地等待exe完成

$check = Start-Process $exe $AllArgs -Wait -Verb runas
Write-Host "end of ps1" + (Get-Date).DateTime
添加WaitForExit调用会导致此错误

You cannot call a method on a null-valued expression.
At line:2 char:1
+ $check.WaitForExit()
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
然而,这确实有效

$p = New-Object System.Diagnostics.Process
$pinfo = New-Object System.Diagnostics.ProcessStartInfo("C:\PowerShell-Wait-For-Exe\bin\Debug\PowerShell-Wait-For-Exe.exe","");
$p.StartInfo = $pinfo;
$p.Start();
$p.WaitForExit();
Write-Host "end of ps1" + (Get-Date).DateTime

我想您可能混淆了启动进程powershell命令和.NET framework进程对象

,我怀疑安装程序生成了另一个进程来进行安装。因此,看起来最后一个进程是赢家。前两个似乎根本不起作用。然而,我把这两个问题搞混了。谢谢你的澄清。我想谷歌并非一直都是我的朋友。