When chaining GnuWin32 commands in Windows cmd.exe, you may encounter strange error messages like this:
> ls | grep … ls: write error: Invalid argument
The first command reports a write error
but the error is really in the second command after the pipe symbol.
You may also encounter a similar write error if the wrong command is found in your PATH variable. For instance, Windows and GnuWin32 both have a find and sort command which support different command-line options, so depending on the order of directories listed in your PATH variable, one version or the other is used. If you enter the wrong command-line options for these commands, they won't start and cause the command earlier in the chain to report some sort of I/O error.
I get these errors all the time, which is pretty frustrating. I double checked and all executables used are the GnuWin32 ones.
ReplyDeleteConsider the following fairly simple command:
cat list_of_files.txt | sed "s/\\/\//g" | xargs grep -i "foo"
(sed makes forward slashes because xargs can't handle back slashes as path separators)
Result:
sed: couldn't write 71 items to stdout: Invalid argument
cat: write error: Invalid argument
WTF?!
To me it seems xargs (is says GNU xargs version 4.2.20) is buggy. As soon as I replace it with (e.g.) 'cat', the whole command line works.
I encountered the same issue.
ReplyDelete