"For" with "usebackq" not using backticks

I have a batch file that worked quite happily until the last two starts, and now it is not. The violation code is as follows:

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 ) ) 

And the error I get is

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

I am sure that I did not make any changes to these lines, since it worked the last time, and I do not see anything bad in this code.

Can someone determine what is wrong or suggest a parameter that I might have accidentally changed, which affects usebackq?

+7
windows batch-file
source share
1 answer

This is an error invoking a child instance of cmd.exe.
You need to use a workaround to avoid the first token using unshielded spaces.

The easiest way is to use CALL , as it moves your program token to second place, and there it works without problems.

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

Windows start command cannot execute batch file

+3
source share

All Articles