windows - 从当前脚本打开另一个 powershell 终端以执行当前脚本输出
问题描述
$argList = "-file `"C:\Users\bdl\Desktop\jhansi\PowerShell_Scripts\dialog.ps1`""
Start powershell -argumentlist $argList -NoNewWindow
我正在尝试从当前脚本打开另一个 powershell 终端以执行当前脚本输出。另一个 powershell 终端正在打开,但它一直在闪烁。我写了上面两行代码,但它在闪烁。请告诉我上面两行中的错误在哪里。
解决方案
你可以尝试这样的事情:
$ArgList = "C:\Users\bdl\Desktop\jhansi\PowerShell_Scripts\dialog.ps1"
Start-Process -FilePath PowerShell -ArgumentList $ArgList -NoNewWindow -Wait
您还可以通过在其中添加退出代码来检查在 PowerShell 中调用的脚本是否成功返回(退出 0 表示成功,退出 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 以外的退出代码意味着脚本没有正确完成。
推荐阅读
- google-maps - Google map API v3 3.37 版会导致“堆栈空间不足”,而旧版本不会
- chef-infra - 是否有 API 可以获取活动的厨师客户端运行详细信息?
- python - IndentationError: unindent 不匹配 python 3 中的任何外部缩进级别,idk 原因
- java - 如何用简单的方式重写一个黄瓜场景?
- python - 在 SciPy 中进行 Delauny 三角剖分后,我如何获得面和顶点?
- javascript - 在下拉菜单中将子列表项与父项对齐
- java - 如何修复 no javabridge no module 错误?如何查找和设置jdk路径?
- java - 退出方法/进程而不调用 exit() 方法
- r - 在 Rstudio 中保存 R 脚本
- node.js - 如何修复 Windows 10 中的“rimraf 不是可识别的命令”