powershell - 如何抑制上一个命令的退出 0?
问题描述
我有两个 powershell 脚本。
script1 是一个脚本,它应该是一个包装器并将参数传递给 script2。script2 根据传递的参数生成数据。
script1 当前有一个 for 循环,它迭代如下命令:
foreach()
{
cmd /c "openPS.bat script2.ps1 $($someParam[-1])"
}
每次该命令成功运行时,它都会输出 exit 0
如您所见,在其中一次运行中,script2 中出现错误,我指定exit 1 + $error[0]
在出现错误/异常时输出。但在 script2 中我没有指定出口 0。只有出口 1(错误)。
我阅读了| out-null
在命令后使用的建议,但问题是来自 script2 的错误不再被输出/报告。
我可以说类似的话cmd /c "openPS.bat script2.ps1 $($someParam[-1]) | out-null only exit 0
吗?
解决方案
if((cmd /c "openPS.bat script2.ps1 $($someParam[-1])") -match "0"){Out-Null}
推荐阅读
- vb.net - 在 VB.NET 中追加文本列表
- regex - 我如何只选择特定的单词?
- android - 您需要至少调用一次 create() 来创建单例
- java - Thymeleaf 模板 th:data=http://www.somesite.com || org.thymeleaf.exceptions.TemplateProcessingException:无法解析为分配序列
- firebase - 是否可以从后端更改 Firebase Analytics 用户属性?
- java - SockJsClient 抛出 ClassCastException
- css - 带有固定侧边栏的 CSS 网格
- r - R使用XML2将数据从XML提取到数据框
- javascript - 不同类型的对象数组
- vb.net - 根据不同的复选框组合显示消息