I’m trying to write a Windows cmd.exe
script to count the occurrences of aes
after compiling a program from the command line. Its simply an Audit/QA script to ensure we’re getting what we expect.
When I use findstr
without the pipe, it appears to work fine:
cryptopp-5.6.3>dumpbin /disasm Win32/cryptlib/Debug/rijndael.obj | findstr aes
000000C1: 66 0F 3A DF C0 00 aeskeygenassist xmm0,xmm0,0
00000206: 66 0F 3A DF C0 00 aeskeygenassist xmm0,xmm0,0
00000345: 66 0F 38 DB 04 81 aesimc xmm0,xmmword ptr [ecx+eax*4]
00000366: 66 0F 38 DB 04 81 aesimc xmm0,xmmword ptr [ecx+eax*4]
0000039F: 66 0F 38 DB 04 81 aesimc xmm0,xmmword ptr [ecx+eax*4]
00000078: 66 0F 38 DC C8 aesenc xmm1,xmm0
000000AB: 66 0F 38 DC C8 aesenc xmm1,xmm0
...
As soon as I pipe the result to find /c
to count occurrences, things blow up. Not only does find
not work as expected, it manages to break the proceeding findstr
command.
cryptopp-5.6.3>dumpbin /disasm Win32/cryptlib/Debug/rijndael.obj | findstr aes | find /c aes
FIND: Parameter format not correct
FINDSTR: Write error
According to find /?
:
If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.
How do I pipe the output of findstr
to the input of find
?
C:bin>find —help
Usage: find [path…] [expression]default path is the current directory; default expression is -print
expression may consist of: operators, options, tests, and actions:operators (decreasing precedence; -and is implicit where no others are given):
( EXPR ) ! EXPR -not EXPR EXPR1 -a EXPR2 EXPR1 -and EXPR2
EXPR1 -o EXPR2 EXPR1 -or EXPR2 EXPR1 , EXPR2positional options (always true): -daystart -follow
normal options (always true, specified before other expressions):
-depth —help -maxdepth LEVELS -mindepth LEVELS -mount -noleaf
—version -xdev -ignore_readdir_race -noignore_readdir_racetests (N can be +N or -N or N): -amin N -anewer FILE -atime N -cmin N
-cnewer FILE -ctime N -empty -false -fstype TYPE -gid N -group NAME
-ilname PATTERN -iname PATTERN -inum N -iwholename PATTERN -iregex PATTERN
-links N -lname PATTERN -mmin N -mtime N -name PATTERN -newer FILE
-nouser -nogroup -path PATTERN -perm [+-]MODE -regex PATTERN
-wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N
-used N -user NAME -xtype [bcdpfls]actions: -exec COMMAND ; -fprint FILE -fprint0 FILE -fprintf FILE FORMAT
-fls FILE -ok COMMAND ; -print -print0 -printf FORMAT -prune -ls -delete
-quitReport (and track progress on fixing) bugs via the findutils bug-reporting
page at http://savannah.gnu.org/ or, if you have no web access, by sending
email to bug-findutils@gnu.org.
Just curious, why does this happen? If I run:
netstat -an | find "443"
into a command prompt, «443» connections are displayed ok. If I run the same command in a PowerShell console or ISE, I get the error «FIND: Parameter format not correct». Is netstat output not being piped properly to find in PS?
Note: If I run netstat -an | findstr "443"
or netstat -an | select-string "443"
in PS those work as expected.
jscott
24.3k8 gold badges78 silver badges99 bronze badges
asked Feb 18, 2016 at 23:57
2
PowerShell evaluates the content within double quotes to perform any variable expansion, sub-expressions, etc, then it discards those double quotes. What PowerShell returns from "443"
is literally 443
(note the missing quotes). FIND.EXE
requires the search string enclosed with double quotes.
If you want to prevent PowerShell from stripping the double quotes use the grave accent (`) to escape them.
netstat -a -n | find `"443`"
You may also use the --%
parameter to perform the escape. Requires PowerShell 3+.
nestat -a -n | find --% "443"
answered Feb 19, 2016 at 2:47
jscottjscott
24.3k8 gold badges78 silver badges99 bronze badges
3
I am using cygwin in my windows machine. I am trying to do a find and it is giving parameter format not correct. Why is that?
$ ls
bootstrap.jar
catalina-tasks.xml
catalina.bat
catalina.sh
commons-daemon-native.tar.gz
commons-daemon.jar
cpappend.bat
digest.bat
digest.sh
setclasspath.bat
setclasspath.sh
shutdown.bat
shutdown.sh
startup.bat
startup.sh
tomcat-juli.jar
tomcat-native.tar.gz
tool-wrapper.bat
tool-wrapper.sh
version.bat
version.sh
$ find . -name "version.sh"
FIND: Parameter format not correct
- Should I install anything while installing cygwin or am I doing something wrong?
asked May 2, 2012 at 22:04
Your PATH
is bad. It has Windows system directories before Cygwin directories, or maybe doesn’t have Cygwin directories at all. This message comes from the Windows command find
(that it reports its name as FIND
in uppercase is a hint).
When you start a Cygwin shell, you usually need to set the PATH
. I recommend that you start a login shell (if I recall correctly, that’s what the default Cygwin system menu entries do). Your Cygwin PATH
should have /usr/local/bin
, /usr/bin
and /bin
(at least) ahead of any non-Cygwin directory.
answered May 2, 2012 at 23:18
3
Is find installed? What does «which find» return? Remember that Windows has a built-in command line find that Cygwin would end up using if its own find is mia.
answered May 2, 2012 at 22:15
The answer from Gilles is correct in that the Windows version of the find
command comes before the cygwin version, and so that is being called.
Putting Cygwin ahead however will mean that any batch files that use the windows find
command will now actually call the cygwin find
command, which may not be what you want.
The most symbiotic way for both to work, in my opinion, is to do the below:
- Locate the cygwin
find
command and rename/copy it to
lfind.exe
(or any other name that isn’t onthe windows PATH) - In your
~/.bashrc
file add the linealias find=lfind
This way, when you run find
from the cygwin terminal you will use the cygwin version, but batch files will use the windows version.
Note: You’ll still need the cygwin bin directory on your PATH, but it can now be further back from the windows system directory.
answered Aug 19, 2015 at 9:57
When you’re installing Cygwin, it doesn’t install all the possible packages unless you ask it to. In order to add a desired package, take a look at the explanation
here on Super User.
Or just perform the following actions:
- Start Setup, select a mirror, and get to the packages screen
- Select «Keep» from the radio button list at the top
- Select the desired package under the relevant group
- Select «Continue»
answered May 2, 2012 at 22:28
Eugene SEugene S
3,3948 gold badges28 silver badges35 bronze badges
Here are the GNU-utils as native win32 ports. They don’t need cygwin to be run, and come with a shell (sh.exe), including grep, sed, awk, find, less, cat, tac, and much more.
The problem with the Windows path will persist, but maybe you rename the find to gfind
(gnu-find) or to search
, to make it more easily accessible, and add the coreutils dir to your PATH.
answered May 3, 2012 at 2:09
user unknownuser unknown
10k2 gold badges33 silver badges58 bronze badges
Я пытаюсь написать сценарий Windows cmd.exe
для подсчета случаев возникновения aes
после компиляции программы из командной строки. Это просто скрипт Audit/QA, чтобы гарантировать, что мы получаем то, что ожидаем.
Когда я использую findstr
без канала, он работает нормально:
cryptopp-5.6.3>dumpbin /disasm Win32/cryptlib/Debug/rijndael.obj | findstr aes
000000C1: 66 0F 3A DF C0 00 aeskeygenassist xmm0,xmm0,0
00000206: 66 0F 3A DF C0 00 aeskeygenassist xmm0,xmm0,0
00000345: 66 0F 38 DB 04 81 aesimc xmm0,xmmword ptr [ecx+eax*4]
00000366: 66 0F 38 DB 04 81 aesimc xmm0,xmmword ptr [ecx+eax*4]
0000039F: 66 0F 38 DB 04 81 aesimc xmm0,xmmword ptr [ecx+eax*4]
00000078: 66 0F 38 DC C8 aesenc xmm1,xmm0
000000AB: 66 0F 38 DC C8 aesenc xmm1,xmm0
...
Как только я отправляю результат, чтобы find /c
для подсчета вхождений, все взрывается. Мало того, что find
не работает , как и ожидалось, он сумел разбить команду исходя findstr
cryptopp-5.6.3>dumpbin /disasm Win32/cryptlib/Debug/rijndael.obj | findstr aes | find /c aes
FIND: Parameter format not correct
FINDSTR: Write error
По словам find /?
:
If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.
Как мне передать вывод findstr
на вход find
?