【发布时间】:2015-10-05 14:30:30
【问题描述】:
我正在尝试在 PowerShell ISE 中调试脚本,但我遇到了一个问题,即一行的正常输出被 ISE 解释为错误
我已经能够简化此问题的重现: 我在https://www.openssl.org/related/binaries.html 获得了任何版本的openssl(我使用来自链接存储库http://slproweb.com/products/Win32OpenSSL.html 的1.0.2d x86 对此进行了测试)
我打开 Powershell ISE,导航到 exe 所在的位置并运行以下命令:
$ErrorActionPreference = "Stop"
$env:OPENSSL_CONF = ((Resolve-Path "openssl.cfg").Path)
&openssl.exe genrsa
输出是红色的,开始是这样的:
openssl.exe : Loading 'screen' into random state - done
At line:1 char:1
+ &C:\Trayport\OpenSsl\openssl.exe genrsa
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Loading 'screen...om state - done:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Generating RSA private key, 2048 bit long modulus
如果我在普通的 PowerShell 命令窗口中运行它,输出是一样的,但是是白色的,不被认为是错误
Loading 'screen' into random state - done
Generating RSA private key, 2048 bit long modulus
我尝试过使用 2>&1 或使用 ErrorPreference 参数封装调用(如 PowerShell ISE throws an error on git checkout 中所建议的那样),但仍然失败
尝试/捕获所有异常确实有效,但如果可以避免,我宁愿不这样做。
我尝试过使用 PowerShell 3.0 和 4.0 版
编辑:如果您使用$ErrorActionPreference = "SilentlyContinue",它确实会消除错误,但随后您将无法访问输出,而且合法问题也会消失
【问题讨论】:
-
那里没有我的问题的答案。 2>&1 对我不起作用。
标签: powershell openssl powershell-3.0 powershell-ise powershell-4.0