Computing.Net > Forums > Programming > Variables in Batch Files

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

Variables in Batch Files

Reply to Message Icon

Original Message
Name: Ford-p
Date: May 19, 2006 at 15:59:23 Pacific
Subject: Variables in Batch Files
OS: Windows XP Pro SP2
CPU/Ram: P4 1.6GHz CPU 1GIG RAM
Comment:

Hey,

I'm relatively new to batch file programing and I am tearing my hair out over this.

I want to be able to set the results of a command as a variable. For example be able to have the results of VER (Microsoft Windows XP [Version 5.1.2600]) as %VER%.
The closest I can get is the following:

VER > ver.txt
FOR /F "TOKENS=*" %%A IN ('TYPE ver.txt') DO (
SET VER=%%A
)

Any help for a simpler method would be much appreciated :)


Report Offensive Message For Removal


Response Number 1
Name: ghostdog
Date: May 19, 2006 at 18:19:09 Pacific
Reply: (edit)

for /F "tokens=* " %%i in ('ver') do (
set VER=%%i
)


Report Offensive Follow Up For Removal

Response Number 2
Name: Ford-p
Date: May 19, 2006 at 18:22:07 Pacific
Reply: (edit)

Thank you just what I was looking for! :)


Report Offensive Follow Up For Removal

Response Number 3
Name: Mechanix2Go
Date: May 20, 2006 at 00:06:35 Pacific
Reply: (edit)

Or this; shorter, but not necessisarily better:

ver>#
set /p ver=<#


If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal

Response Number 4
Name: Ford-p
Date: May 20, 2006 at 08:23:31 Pacific
Reply: (edit)

Thanks for that too, works really well :D


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software