中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-23 13:38
47,812 topics / 349,917 posts / today 0 new / 48,273 members
DOS批处理 & 脚本技术(批处理室) » Ask how to store the result of a command in a variable
Printable Version  2,141 / 6
Floor1 tired_bird Posted 2004-11-02 00:00
中级用户 Posts 58 Credits 307
Ask how to store the result of a command in a variable?
I want to put the result of the command echo.|date|LMOD /L* into a variable. Can this be done?
Also hope to be taught, thank you first!
Floor2 龙王 Posted 2004-11-03 00:00
银牌会员 Posts 334 Credits 1,186
::Save the date as a text
echo.|date|lmod /l* >date.txt
::Assign the content of the text to the variable %date%
type|date.txt|lmod set date=
Floor3 tired_bird Posted 2004-11-03 00:00
中级用户 Posts 58 Credits 307
Floor4 Climbing Posted 2004-11-03 00:00
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
There is no need to take a detour to set it. It can be directly like this: echo. | date | lmod /L1 set mydate= > temp.bat
call temp.bat
del temp.bat
echo %mydate%
Floor5 tired_bird Posted 2004-11-03 00:00
中级用户 Posts 58 Credits 307
Floor6 龙王 Posted 2004-11-04 00:00
银牌会员 Posts 334 Credits 1,186
Using lmod itself is a detour, and the solution using third-party software was pioneered by willsort. You can search for the original post.

The following is the batch script I modified:
echo set date=%4 >current.bat
echo.|date|find/i "current" >setdate.bat
call setdate.bat
del current.bat
del setdate.bat

Floor7 Climbing Posted 2004-11-04 00:00
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
Yes, using lmod is a detour, but if you can take one detour, you don't need to take two. That's what I mean. Any method has limitations. For example, the following situation:
D:\>echo.|date
Current date: 2004-11-04
Enter new date: (year-month-day)
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023