问题
When I run the following command (or any command with a pipe | in it) on my machine:
dir | findstr "Directory"
I get the following message:
The filename, directory name, or volume label syntax is incorrect.
Running dir command or findstr command by themselves works just fine.
The volume label is:
vol
Volume in drive C is OSDisk
Volume Serial Number is 685C-A5B5
The version is:
ver
Microsoft Windows [Version 6.1.7601]
回答1:
As previously mentioned by @dbenham You need to make sure your COMSPEC variable has correct values defined.
It should have the following value:
%SystemRoot%\system32\cmd.exe
You can check it by Right Clicking My Computer-->Properties--->Advanced System Properties-->Environment Variables
If You don't find COMSPEC there, create a new variable by giving the above mentioned value i.e. %SystemRoot%\system32\cmd.exe
Good Luck
回答2:
Check your COMSPEC variable. It should contain the full, absolute path (including file name) to CMD.EXE. Each side of a pipe is executed via a new CMD.EXE thread that is launched via the COMSPEC value.
来源:https://stackoverflow.com/questions/15258695/when-using-pipe-getting-the-filename-directory-name-or-volume-label-syntax-is