Assign command output to variable in dos .bat (cmd) shellBy neokrates, written on November 10, 2010 |
howto |
- neokrates
- Email: uwarov@yahoo.com
- Website: http://www.thinkplexx.com
- Join date: 05-31-09
- Posts: 20
Rate it
Ad
Poll
Your favorite way to manage packages is?
- Something else (100%, 9 Votes)
- Tarball command Line (0%, 0 Votes)
- Debian Dpkg command Line (0%, 0 Votes)
- Manually (0%, 0 Votes)
- Synaptic (0%, 0 Votes)
- Adept (0%, 0 Votes)
- Apt-get command line (0%, 0 Votes)
Total Voters: 9
Loading ...
Most popular search terms:
Works for:
Windows XP cmd shell
Should also work for:
any cmd or command shell
I have two unix-like tools which can extend my scripting under DOS, here::
c:\test > dir 13.10.2010 08:51 39.424 date.exe 13.10.2010 08:51 57.856 ls.exe 10.11.2010 18:00 535 test.bat
What I want is to assign the standard command output from these tools to variable for further processing. Here is one way to do that:
@echo off
echo.
echo.
call :_DATE
echo [DATE]:
echo %result%
echo.
call :LS_FILE
echo [LS]:
echo %result%
echo.
goto :EOF
:_DATE
FOR /F "tokens=1 delims=" %%A in ('date.exe') do SET result=%%A
GOTO :eof
:LS_FILE
FOR /F "tokens=1 delims=" %%A in ('ls.exe --full-time -l %*') do SET result=%%A
GOTO :eof
Have fun!
|
LEARN MORE (amazon bookstore)
|
|
TAGS
|
|
SOCIAL
|


















