Skip to main content
gamedev.net
🔒 Locked

BATCH script variable woes!

Started by mrmrcoleman Jun 28, 2007 at 12:38 PM 4 replies 4.9k views
Original Post
mrmrcoleman
mrmrcoleman
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
Zahlman
Zahlman
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.
mrmrcoleman
mrmrcoleman
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
rip-off
rip-off
You could use a real language perhaps? Like ruby or python etc...
LessBread
LessBread
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.

"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
mrmrcoleman
mrmrcoleman
rip-off: I don't know those languages and this is a very small script.

LessBread: Thanks for the link.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.