I am trying to call a function present in saur.exe using bat. It looks something like this:
saur.exe readName
When i execute it, it returns a string "Saurabh".
Now that I want to store "saurabh" in a variable called name
开发者_如何学Python.
So I am doing :
set name = saur.exe readName
echo .%name%
In this case, it doesnot execute. It gives blank in front of echo command.
For some strange reason, doing what you want requires some awkward workarounds. The long way would be to store the output of the command in a file, then read the file into the variable, and finally delete the file. The shorter (and barely readable) way is:
for /f "delims=" %%a in ('saur.exe readName') do set name=%%a
echo %name%
:-(
Some SET command documentation will show that you can only assign strings to environment variables (http://www.computerhope.com/sethlp.htm).
In your example above, you have actually set an environment variable called:
"name "
Yet you are echoing the variable:
"name"
The best solution I can find is to do something similar to
saur.exe readName>tempFile
SET /p variableName=<tempFile
ECHO %variableName%
Hopefully this helps :)
精彩评论