只是好奇,为什么会这样呢? 如果我运行:
netstat -an | find "443"
进入命令提示符,“443”连接显示OK。 如果我在PowerShell控制台或ISE中运行相同的命令,则会出现“FIND:参数格式不正确”错误。 netstat输出没有正确pipe道find在PS?
注意:如果我运行netstat -an | findstr "443" netstat -an | findstr "443"或netstat -an | select-string "443" PS中的netstat -an | select-string "443"按预期工作。
PowerShell评估双引号内的内容以执行任何variables扩展,子expression式等,然后放弃这些双引号。 PowerShell从"443"返回的字面意思是443 (注意缺less的引号)。 FIND.EXE 需要用双引号括起来的searchstring。
如果你想阻止PowerShell去除双引号,使用重音符(`)来转义它们。
netstat -a -n | find `"443`"
您也可以使用--%参数来执行转义。 需要PowerShell 3+。
nestat -a -n | find --% "443"