BATCH script variable woes!
Hello,
I am trying to get the result of a call to hostname in DOS into a variable.
Typing hostname on the command line give me
PC-COLEMANM which is exactly what I want, but I need to be able to put this in a variable.
So far I have tried:
SET HOST=hostname
SET HOST="hostname"
SET HOST=`hostname`
SET HOST='hostname'
And all of the above with '.exe' appended. Unfortunately instead of getting the result of the hostname call I just get whatever is on the right hand side of the equals sign.
Does anybody know how I can get this working?
Kind regards,
Mark
DOS batch scripting is the worst thing ever.
This is the only way I know to make it work:
for /f %i in ('hostname') do (set HOST=%i)
In a script, you'll need to double up one of the percentage signs, or possibly both, although you should not when you do it from the command line.
I told you - worst thing ever.
This is the only way I know to make it work:
for /f %i in ('hostname') do (set HOST=%i)
In a script, you'll need to double up one of the percentage signs, or possibly both, although you should not when you do it from the command line.
I told you - worst thing ever.
I actually couldn't agree more about DOS batch scripting being god awful, but unfortunately I am stuck with it as I can't do what I need to with Cygwin.
The code worked, and you were right about the extra %i, it was needed at the end.
Big thanks,
Mark
The code worked, and you were right about the extra %i, it was needed at the end.
Big thanks,
Mark
Batch files are so much easier to work with on NT based systems - NT/W2K/XP
There are a ton of batch file examples here: Rob van der Woude's Scripting Pages.
Maybe one of them does what you want.
There are a ton of batch file examples here: Rob van der Woude's Scripting Pages.
Maybe one of them does what you want.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement