从当前脚本打开另一个powershell终端,执行当前脚本输出


$argList = "-file `"C:UsersbdlDesktopjhansiPowerShell_Scriptsdialog.ps1`""
Start powershell -argumentlist $argList -NoNewWindow

我正在尝试从当前脚本打开另一个powershell终端来执行当前脚本输出。另一个powershell终端正在打开,但是一直在闪烁。上面的两行代码我已经写了,但它是闪烁的。请告诉我以上两行错误在哪里。

您可以尝试这样做:

$ArgList = "C:UsersbdlDesktopjhansiPowerShell_Scriptsdialog.ps1"
Start-Process -FilePath PowerShell -ArgumentList $ArgList -NoNewWindow -Wait

你也可以通过添加一个退出代码来检查在PowerShell中调用的脚本是否成功返回(exit 0表示成功,exit 1表示失败):

$Exe = (Start-Process -FilePath PowerShell -ArgumentList $ArgList -NoNewWindow -Wait -PassThru).ExitCode
If ($Exe -ne 0)
{
Write-Host "An error has occured while running the script."
}

如果退出码不是0,则表示脚本没有正确完成。