You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell中替代Bash /dev/null输入重定向避免程序等待输入的方案

PowerShell 等价命令实现方案

通用兼容写法(支持所有PowerShell版本)

直接通过管道向openssl进程传入$null代替Bash中的</dev/null即可,完整命令如下:

$null | .\openssl s_client -showcerts -connect host:port 2>$null | .\openssl x509 -noout -dates

写法说明

  • $null | 完全等价于Bash语法中的</dev/null:向进程的标准输入传入空的EOF标识,进程接收到结束标识后就不会持续等待输入,解决卡死问题
  • 你原有写法中的2>$null是正确的,等价于Bash中的2>/dev/null,作用是丢弃标准错误输出

高版本可选写法(仅PowerShell 7.3+支持)

如果你的PowerShell版本在7.3及以上,也可以使用内置的输入重定向参数实现:

.\openssl s_client -showcerts -connect host:port -RedirectStandardInput $null 2>$null | .\openssl x509 -noout -dates

内容的提问来源于stack exchange,提问作者GhostJumper

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 10:54:04