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.
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.
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%
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.
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"
Bookmarks