-1

I am looking for way to assign output of a command to a batch variable, but the command internally uses another variable.

When i use the solution specified in Assign Command output to Variable in Batch file

I am getting error that the variable inside the command was not expected at this time.

Please help

1
  • 2
    It would help to know what command you're trying to use, and exactly how it isn't working. Commented Feb 22, 2015 at 23:53

1 Answer 1

0

I think this will work for you.

Say you command was Echo hi and you wanted to store the output ('hi') into a variable:

Echo hi > out.tmp
set /p var=< out.tmp
del out.tmp

Echo %var%

where var now stores the value of your output. Note: it will only store the first the line of output. If you want to do last line of output comment and I would make it use a for loop instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.