I'm pretty sure git will include a newline in the output, so even if you got the SET /P to print your "
, your output would be:
"v1.0
"
I believe the simplest solution to your problem is to capture the output of your git command with FOR /F, and then write your quoted value within the loop.
@echo off
cd /d "c:path to project directory"
for /f "delims=" %%A in ('git describe') echo "%%A" >file.txt
Below are some issues with your posted code:
You wanted to launch git with START, and then exit. You used the /K option, which keeps the the new cmd session active after the command executes, so you were forced to append the EXIT command. Much simpler to just use the /C option instead
start cmd.exe /c "git describe >>"file.txt""
But there is no need for START at all. You can simply run the command directly from the current session
git describe >>"file.txt"
You attempted to use SET /P to print out a single "
without a newline. This failed because SET /P has some odd rules for how it handles leading quotes, white space, and =
.
Either of the following could be used to redirect output of a single "
to a file:
<nul >file.txt set /p ="""
<nul >file.txt set /p "=""""
I put the redirection in the front so you don't have to worry about the odd quote turning the redirection into literal strings. If you put the redirection at the end, then you must escape one of the quotes.
set /p =^""" <nul >file.txt
set /p =""^" <nul >file.txt
set /p ^"="""" <nul >file.txt
set /p "="^""" <nul >file.txt
set /p "="""^" <nul >file.txt