"对于"使用" usebackq"不使用反引号

时间:2016-06-23 14:20:30

标签: 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:\程序'不被识别为内部或外部命令,可操作程序或批处理文件。

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

任何人都可以发现错误,或者建议我可能无意中改变了影响usebackq的设置吗?

1 个答案:

答案 0 :(得分:3)

调用子cmd.exe实例的错误 您需要使用变通方法来避免第一个令牌使用未转义的空格。

最简单的方法是使用CALL,因为它会将您的程序令牌移动到第二位,并且它可以正常运行。

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