gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 13:13:00 26 4
gpt4 key购买 nike

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

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com