windows - "For"和 "usebackq"不使用反引号

标签 windows batch-file

我有一个运行得很愉快的批处理文件,直到最后几次运行,但现在不是。 违规代码如下:

set uncommittedchanges=1
for /f "tokens=* usebackq" %%a in (`"C:\Program Files\Git\cmd\git" -C "\my\git\repository" status`) do (
    if "%%a" == "nothing to commit, working directory clean" (
        set uncommittedchanges=0
    )
)

我得到的错误是

'C:\Program' is not recognized as an internal or external command, operable program or batch file.

我确定自从上次运行以来我没有对这些行进行任何更改,并且我看不出代码有任何问题。

谁能发现问题所在,或者建议我可能无意中更改了影响 usebackq 的设置?

最佳答案

是调用子cmd.exe实例的bug。
您需要使用一种解决方法来避免第一个标记使用未转义的空格。

最简单的方法是使用 CALL,因为它将您的程序 token 移动到第二个位置,并且它可以正常工作。

for /f "tokens=* usebackq" %%a in (`CALL "C:\Program Files\Git\cmd\git" -C "\my\git\repository" status`) do (

Windows start command not able to execute batch file

关于windows - "For"和 "usebackq"不使用反引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37994355/

相关文章:

c# - TFS C# API : Workspace. PendAdd 静默失败

linux - 在 Windows 机器上安装 ubuntu 时出现问题

windows - FIND 命令返回空值

c++ - 避免 DLL 版本控制问题

c++ - 为什么即使我设置了 THREAD_MODE_BACKGROUND_BEGIN,我的程序还是资源消耗大户?

windows - 创建 .bat 文件以清除 apache 日志

Windows7批处理,如何在第一个For循环后中断

batch-file - 批处理 : Copy list of files to another folder

batch-file - 一种在 cmd.txt 文件中使用 PuTTY 批处理对 Cisco 键入多个命令的方法

java - 在 JNA 中使用 GetWindowModuleFileName