在 cmd 上使用 FINDSTR 并输出 PATH 时出现意外错误

Unexpected error using FINDSTR on cmd and outputting PATH

在我编写的脚本中,想要通过在 python 脚本中调用 findstr 来在 .cpp 文件中定位 C++ 函数。我正在项目目录中的 cmd 上手动测试它,其中包含几个 .cpp.h 文件。

通过使用:

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

输出:

target.cpp

我得到了包含函数的正确 .cpp 文件,我们称它为 target.cpp. 。但是我正在编写这个 python 脚本,以便用户以后可以找到某些功能的更改,所以我需要它应该在输出中显示整个路径。在我发现的堆栈溢出解决方案中,我使用了:

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

输出:

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

请注意,如果我使用相同的命令,例如:

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

我得到了所有 .cpp 的列表以及该文件夹和其中使用 bool 类型的子目录中的完整路径(需要什么)。

经过几个小时的头脑风暴:

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

我不是专家,但是当我使用 findstr 中的 /R 选项将我的字符串更改为表达式,然后使用 .* (通配符字符)有效。

问题是,尽管 findstr\" 识别为字符串中的引号字符,但当我在 in(' **findstr command** ') 中使用它时,这会导致 cmd 出现问题其中 3 个引号应作为附加字符串输入。