M
M
mrZurg2016-08-17 12:08:28
git
mrZurg, 2016-08-17 12:08:28

How to write the execution of the git command in a string variable in a bat script?

It is necessary that when you run a bat file containing approximately:
git log --pretty=format:"%%h" -1
The result of the execution is written to a string variable.
The following code doesn't work:

FOR /F "usebackq" %%a IN (' git log --pretty=format:"%%h" -1 ') DO (
 set str1=%%a
)
echo %str1%

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2016-08-17
@OLS

Read about SetLocal EnableDelayedExpansion, it seems to me that all your problems are related to it.
For example, in this example, everything was very similar
PS And as far as I understand, you wanted to glue, and inside the loop your variable is simply overwritten.

O
Olgeir, 2016-08-17
@Olgeir

instead of "usebackq" write "tokens=* delims="

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question