Question

Im in Windows Server 2003 and using below commands to fetch string matching lines in files created today in a specific directory.

forfiles -p D:\ -m *.1  -d +0 -c "cmd /c findstr /i /c:\"Hey Hi\" @FILE" >> txt5.txt
or
forfiles -p D:\ -m *.1  -d +0 -c "cmd /c grep \"Hey Hi\" @FILE" >> txt5.txt

Geeting error 'FINDSTR: Write error' and 'grep write error bad file descriptor' respectively for both commands. So basically the commands work i.e. display the output in screen but unable to redirect the output to a file.

I did not find suitable solution though users reported this same error for different scenarios. Any help is appreciated. Thanks in advance!

Was it helpful?

Solution

You should be able to remove the cmd /c; I don't see any reason you'd need a new copy of the command shell open for the findstr call.

This works for me correctly at the command prompt:

forfiles -m t*.xml -d +0 -c "findstr /i "Item" @file" >> out.txt. 

It produces an out.txt file that contains the proper content matching the search criteria.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top