1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

save text file as a variable

Discussion in 'DOS/Other' started by JimZ, Jan 30, 2007.

Thread Status:
Not open for further replies.
Advertisement
  1. JimZ

    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?
     
  2. JohnWill

    JohnWill Retired Moderator

    Joined:
    Oct 19, 2002
    Messages:
    106,418
    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?
     
  3. JimZ

    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.
     
  4. Squashman

    Squashman 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%
     
  5. JohnWill

    JohnWill Retired Moderator

    Joined:
    Oct 19, 2002
    Messages:
    106,418
    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.
     
  6. Sponsor

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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/539747

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice