save text file as a variable

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

JimZ

Thread Starter
Joined
Jun 26, 2003
Messages
174
Is there anyway to save the output of a DOS command to a variable file name. Such as %hostname%.txt Anyone know of anything possible?
 

JohnWill

Retired Moderator
Joined
Oct 19, 2002
Messages
106,429
dir >c:\hostname.txt

The above command saves the directory listing the that name in the root of C: Most other commands will accept the same redirection character.

Redirection is dependent on exactly what command you're running, can you be more specific?
 

JimZ

Thread Starter
Joined
Jun 26, 2003
Messages
174
I want to have the file name be a variable. Such as dir > C:\hostname.txt I need to have a machine unique filename. I have a script that saves a log file, I need to run this script locally on 30 machines on a regular basis. Right now I think it will be easier to have a single script that saves the log to a single location. The unique file name will help me sort which machine each log came from.
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
Environmental Variables. Type set at a cmd prompt. You can use those variables in a batch file.
%COMPUTERNAME%
 

JohnWill

Retired Moderator
Joined
Oct 19, 2002
Messages
106,429
What I would do if the bare name is in the file in question is the following.

Create a file named SET.TXT with the text "SET=MYVAR " (without the quotes) and save it.

COPY SET.TXT+C:\HOSTNAME.TXT SETCMD.BAT
CALL SETCMD

This will set the environment variable MYVAR to the file name in question.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top