【问题标题】:Running openssl commands in PowerShell在 PowerShell 中运行 openssl 命令
【发布时间】:2018-04-21 18:43:58
【问题描述】:

我正在 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 命令并将输出忽略或至少不解释为命令的最佳方法是什么?

【问题讨论】:

  • 如何尝试让 powershell 脚本运行而没有错误不是又是一个编程问题?

标签: windows powershell command


【解决方案1】:

您不需要Invoke-Expression(实际上,it's not recommended 除非在特定情况下,因为它容易被注入)。只需运行命令并在需要变量字符串扩展的地方引用参数:

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

要忽略命令的输出,一种常见的技术是通过管道传送到Out-Null

【讨论】:

  • 谢谢 - 不是很熟悉 powershell。我计划明天阅读有关调用表达式与调用命令的内容。我试试看。
  • 谢谢。我已经阅读了它们,看看它们是如何毫无意义和风险的。另外,仅供参考-我尝试将这些命令传递给 Out-Null,但它没有用。但是,将命令附加到 2>&1 确实如此。再次感谢您。
  • Out-Null 不重定向标准错误,IIRC。
  • 在此命令上使用 | Out-Null 只会抑制部分输出。仍然有一些输出被解释为错误....还有什么想法吗?
  • 如果您不想从源代码构建,您可以从哪里安全地获取openssl 二进制文件?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-16
  • 2011-03-02
  • 2015-03-12
  • 1970-01-01
  • 1970-01-01
  • 2021-06-19
相关资源
最近更新 更多