I'm executing the following command in PowerShell:
Invoke-Expression "openssl pkcs12 -in $certCN.pfx -nocerts -nodes -out $certCN.key -password pass:1111"
It works fine, however the output from openssl
is causing ugly console errors:
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
What's the best way to execute this OpenSSL command and have the output ignored or at least not interpreted as a command?
答案 0 :(得分:7)
您不需要Invoke-Expression
(事实上,it's not recommended除非在特定情况下因为它易于注射)。只需运行命令并引用需要变量字符串扩展的参数:
openssl pkcs12 -in "$certCN.pfx" -nocerts -nodes -out "$certCN.key" -password pass:1111
要忽略命令的输出,一种常用技术是管道到Out-Null
。
答案 1 :(得分:-5)
我发布这篇文章五分钟后发现了这篇文章:
显示简单地说
2>&1
在字符串的末尾,将成功和错误重定向为null:
Invoke-Expression "openssl pkcs12 -in $certCN.pfx -nocerts -nodes -out $certCN.key -password pass:1111" 2>&1
根据我的需要为冠军工作。