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
相关产品推荐
相关产品推荐

