繁体   English   中英

在PowerShell中运行openssl命令

[英]Running openssl commands in PowerShell

我正在PowerShell中执行以下命令:

Invoke-Expression "openssl pkcs12 -in $certCN.pfx -nocerts -nodes -out $certCN.key -password pass:1111"

它工作正常,但是openssl的输出导致难看的控制台错误:

openssl : MAC verified OK
At line:1 char:1
+ openssl pkcs12 -in www.mywebsite.com.pfx -nocerts -node ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (MAC verified OK:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

执行此OpenSSL命令并忽略输出或至少不将其解释为命令的最佳方法是什么?

您不需要Invoke-Expression (实际上,除特殊情况下, 不建议使用 Invoke-Expression ,因为它易于注入)。 只需运行命令并在需要可变字符串扩展的地方引用参数:

openssl pkcs12 -in "$certCN.pfx" -nocerts -nodes -out "$certCN.key" -password pass:1111

要忽略命令的输出,一种常用技术是将管道传递给Out-Null

在发布此消息五分钟后,我发现了以下文章:

http://www.jonathanmedd.net/2013/07/making-native-executables-in-windows-run-quietly-in-powershell.html

简单地显示

2>&1 

在字符串的末尾将成功和错误重定向为null,例如:

 Invoke-Expression "openssl pkcs12 -in $certCN.pfx -nocerts -nodes -out $certCN.key -password pass:1111" 2>&1

可以满足我的需求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM