Go Back   TechArena Community > Software > Operating Systems
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



Retrieve the result of a DOS command in a variable

Operating Systems


Reply
 
Thread Tools Search this Thread
  #1  
Old 30-01-2010
Member
 
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.
Reply With Quote
  #2  
Old 30-01-2010
Member
 
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%
Reply With Quote
  #3  
Old 30-01-2010
Member
 
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.
Reply With Quote
  #4  
Old 30-01-2010
Raiz's Avatar
Member
 
Join Date: Dec 2008
Posts: 1,111
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"
Reply With Quote
Reply

  TechArena Community > Software > Operating Systems


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Retrieve the result of a DOS command in a variable"
Thread Thread Starter Forum Replies Last Post
How can i retrieve result from bprd ? Caryas Networking & Security 6 31-05-2011 08:45 PM
Retrieve Variable In JSP Amaresh Software Development 4 10-02-2010 09:14 PM
Remove system environment variable using command line ? Vilius Mockûnas Windows Server Help 1 12-06-2009 05:10 PM
How to retrieve a variable in UNIX Kirt Operating Systems 4 02-05-2009 10:25 PM
How to add a variable to a shell command in a vbscript Dee Windows Server Help 4 28-04-2008 10:13 PM


All times are GMT +5.5. The time now is 12:23 AM.