Search code examples
findstr

Unexpected error using FINDSTR on cmd and outputting PATH


In a script that I write, want to locate C++ functions inside .cpp files by calling findstr in a python script. I am testing this manually on cmd inside the project directory where several .cpp and .h files are contained.

by using:

findstr /spinm /C:"werden oder sollen neue Versionen dieser Dateien angelegt werden?\",Project::Plural())" *.cpp

output:

target.cpp

I get the correct .cpp file where the function is contained, let's call it target.cpp. . However I am writing this python script so users can later go find changes on certain functions, so I need it should show whole path in the output . In a solution I found on stack overflow I used:

for /f "delims=" %a in ('findstr /spinm /C:"werden oder sollen neue Versionen dieser Dateien angelegt werden?\",Project::Plural())" *.cpp') do echo %~fa

output:

)" *.cpp') do echo %~fa was unexpected at this time.

Note that if I use the same command such as:

for /f "delims=" %a in ('findstr /spinm /C:"bool" *.cpp') do echo %~fa

I get a list of all the .cpp along with the full path (what is needed) in that folder and sub directories that use the bool type in them.


Solution

  • So after several hours of brainstorming:

    for /f "delims=" %a in ('findstr /spinmr /C:"werden oder sollen neue Versionen dieser Dateien angelegt werden?.*,Project::Plural())" *.cpp') do echo %~fa
    

    I'm not an expert but when I change my string to an expression using /R option in findstr and then use .* (wildcard character) it works.

    Problem was that although findstr recognized the \" as a quotation character inside the string this creates problems with cmd when I use it in in(' **findstr command** ') where 3 quotation marks was expected as an additional string input.