views:

37

answers:

1

Can someone explain to me why this command reports "The syntax of the command is incorrect."? The first part runs fine by itself, so I know it's not that. And the second part looks to be correct according to help find

C:\Program Files\Apache Software Foundation\Apache2.2\logs>type error.log ^| find /C "2010"

I was wondering if it might have to do with line endings in the file, but even something as simple as this gives me the same error:

C:\Program Files\Apache Software Foundation\Apache2.2\logs>echo "Test1" > test.log

C:\Program Files\Apache Software Foundation\Apache2.2\logs>echo "Test2" >> test.log

C:\Program Files\Apache Software Foundation\Apache2.2\logs>echo "Test3" >> test.log

C:\Program Files\Apache Software Foundation\Apache2.2\logs>type test.log
"Test1"
"Test2"
"Test3"

C:\Program Files\Apache Software Foundation\Apache2.2\logs>type test.log ^| find /C "test"
The syntax of the command is incorrect.

C:\Program Files\Apache Software Foundation\Apache2.2\logs>type test.log ^| find /C "Test"
The syntax of the command is incorrect.
+2  A: 

You need to supply the filename to the find command:

find /C "test" test.log

or

type test.log | find /C "test"

Joachim VR
Ah, OK. That works. The example I was basing this off of was using "^|" - how is that different from the pipe character alone?
Chrisbloom7
FWIW, the additional `^` character works in the following context: `C:\Program Files\Apache Software Foundation\Apache2.2\logs>dir /B ^| find /N "*.log"` but that command *doesn't* work w/o the `^`
Chrisbloom7
I believe ^ is a escape character. If you wanted | sign to have no special meaning (piping command executions), you could escape the sign with ^. See http://en.wikipedia.org/wiki/Escape_character#Windows_Command_Prompt
Grzegorz Oledzki
Ah, I see now. The example I was taking this from actually started out as `for /F "tokens=1,2 delims=[] " %%i in ('dir...` so the `^|` was escaping the `|` only within the context of the `for` command. The final interpretation would be just the pipe. Thanks for leading me to that realization.
Chrisbloom7
PS: My previous comment was actually incorrect. The `C:\Program Files\Apache Software Foundation\Apache2.2\logs>dir /B ^| find /N "*.log"` only appeared to work because the pipe was being escaped, so find never actually ran, and the results looked correct because **everything** in that folder is a .log file ^_^
Chrisbloom7