China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 11:14
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Ask how to store the result of a command in a variable View 1,957 Replies 6
Original Poster Posted 2004-11-02 00:00 ·  中国 江苏 南京 秦淮区 电信
中级用户
★★
Credits 307
Posts 58
Joined 2004-10-21 00:00
21-year member
UID 32780
Gender Male
Status Offline
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!
Floor 2 Posted 2004-11-03 00:00 ·  中国 河南 安阳 联通
银牌会员
★★★
Credits 1,186
Posts 334
Joined 2003-05-30 00:00
23-year member
UID 2626
Gender Male
Status Offline
::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=
Floor 3 Posted 2004-11-03 00:00 ·  中国 江苏 南京 秦淮区 电信
中级用户
★★
Credits 307
Posts 58
Joined 2004-10-21 00:00
21-year member
UID 32780
Gender Male
Status Offline
Floor 4 Posted 2004-11-03 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
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%
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 5 Posted 2004-11-03 00:00 ·  中国 江苏 南京 秦淮区 电信
中级用户
★★
Credits 307
Posts 58
Joined 2004-10-21 00:00
21-year member
UID 32780
Gender Male
Status Offline
Floor 6 Posted 2004-11-04 00:00 ·  中国 河南 安阳 联通
银牌会员
★★★
Credits 1,186
Posts 334
Joined 2003-05-30 00:00
23-year member
UID 2626
Gender Male
Status Offline
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

Floor 7 Posted 2004-11-04 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
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)
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Forum Jump: