I have a batch file which was working quite happily, until the last couple of runs, and now it's not. The offending 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 am getting is
'C:\Program' is not recognized as an internal or external command, operable program or batch file.
I'm sure I haven't made any changes to these lines since it was last working, and I can't see anything wrong with the code as it stands.
Can anyone spot what's wrong, or suggest a setting I may have inadvertently changed that affects usebackq?
By default, /F breaks up the command output at each blank space, and any blank lines are skipped.
The "delims=" option means do not parse into tokens (preserve each entire line). So each line is iteratively loaded into the %%i variable.
The cmd token records the list of arguments and the list of environment variables that are associated with a command. The cmd token contains the following fields: A token ID that identifies this token as a cmd token. A count of the command's arguments. The argument list.
It's a bug of the invoking the child cmd.exe instance.
You need to use a workaround to avoid that the first token uses unescaped spaces.
The simplest way is to use CALL
as it moves your program-token to the 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 not able to execute batch file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With