Results 1 to 4 of 4

Thread: Retrieve the result of a DOS command in a variable

  1. #1
    Join Date
    Jan 2009
    Posts
    34

    Retrieve the result of a DOS command in a variable

    hi,

    I'm trying to assign dos ommand output to a single variable . For example i awn to use chdir which display your current working directory and i want something like variable_name= output-of-chdir

    But it doesn't worked for me, any help.

  2. #2
    Join Date
    Oct 2008
    Posts
    44

    Re: Retrieve the result of a DOS command in a variable

    I'm not much expert with DOS but you can try out the following , i found it by searching in google:

    Code:
    for /f "tokens=*" %%a in ('"C:\DOS\time TIME_VAR"') do set YOURVAR=%%a
    echo.%YOURVAR%

  3. #3
    Join Date
    Oct 2008
    Posts
    70

    Re: Retrieve the result of a DOS command in a variable

    Some of you may still have not found the answer to this question ...

    The MS-DOS is not always convenient and it is even quite limited in certain situations. When you want to retrieve the result of a command in a variable to be able to address directly, you have two solutions.

    The first is to write the output into a file and then read it but then forget, there are more effective after all. The command For can process line by line the contents of a file or the result of an order, we will use it:

    For example, if you want to write the result of your command in a variable named result, Do this

    Code:
    for /f "delims=" %%a in ('your command here') do set result=%%a

    Nota: Remember the "single quotes" to each side of your variable.
    Do not forget that %% a not contain a row of the result of your order at each iteration of the loop.

    And now, that's it.

  4. #4
    Join Date
    Dec 2008
    Posts
    1,108

    Re: Retrieve the result of a DOS command in a variable

    Refer to following Microsoft guide, see if it can help you:

    Command prompt (Cmd. exe) command-line string limitation
    The difference between stupidity and genius is that genius has its limits. - Albert Einstein

    What we think, we become (Please don't think you are a superhero and don't try to fly)

    "SUCCESS IS NOT A DESTINATION , IT'S A JOURNEY"

Similar Threads

  1. How can i retrieve result from bprd ?
    By Caryas in forum Networking & Security
    Replies: 6
    Last Post: 31-05-2011, 07:45 PM
  2. Retrieve Variable In JSP
    By Amaresh in forum Software Development
    Replies: 4
    Last Post: 10-02-2010, 09:14 PM
  3. Remove system environment variable using command line ?
    By Vilius Mockûnas in forum Windows Server Help
    Replies: 1
    Last Post: 12-06-2009, 04:10 PM
  4. How to retrieve a variable in UNIX
    By Kirt in forum Operating Systems
    Replies: 4
    Last Post: 02-05-2009, 09:25 PM
  5. How to add a variable to a shell command in a vbscript
    By Dee in forum Windows Server Help
    Replies: 4
    Last Post: 28-04-2008, 09:13 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,704,507.89390 seconds with 17 queries