为什么它们返回不同的结果?关于cmd命令,我遗漏了什么?
PS C:\src\t\cad> Get-ChildItem -Directory -Recurse -Path $Env:ProgramFiles -ErrorAction SilentlyContinue | Measure-Object
Count : 17381
来自cmd.exe的:
10:28:18.87 C:\src\t\cad
C:>powershell -NoProfile -Command "Get-ChildItem -Directory -Recurse -Path '"%ProgramFiles%"' -ErrorAction SilentlyContinue ^| Measure-Object"
Count : 0
发布于 2018-06-02 23:49:09
我认为-ErrorAction SilentlyContinue
抑制了第一个命令中的错误,因此不会向下传递任何内容到Measure-Object
。
在PSCore上测试我得到:
pwsh -command "get-process ^| measure-object"
get-process : Cannot find a process with the name "^".
Count : 0
但是删除'^‘字符:
bash-3.2$ pwsh -command "get-process | measure-object"
Count : 318
因此,我假设Windows PowerShell也是如此。在没有^的情况下尝试
powershell -NoProfile -Command "Get-ChildItem -Directory -Recurse -Path '"%ProgramFiles%"' -ErrorAction SilentlyContinue | Measure-Object"
https://stackoverflow.com/questions/50658456
复制相似问题