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!
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!
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%
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
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)