中国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-08-13 04:59
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS学习入门 & 精彩文章 (教学室) » How can I assign the output of a command to a variable? Thanks
Printable Version  1,011 / 4
Floor1 msg Posted 2003-08-24 00:00
初级用户 Posts 2 Credits 108
I wrote a batch file. The original idea was to display today's date in YYYYMMDD format, but instead it shows type date.txt,

My bat file is as follows:
@call date /t | awk95 -F- "{ print($1 $2 substr($3,1,2)) }">date.txt
@set filename=type date.txt
echo %filename%

Thanks, many thanks
Floor2 iceboy Posted 2003-08-30 00:00
银牌会员 Posts 512 Credits 1,681
If you want to display it on the screen, then use type date.txt...
If you want to assign it to a variable... you may need to write a small program in QB
Floor3 willsort Posted 2003-08-30 00:00
元老会员 Posts 1,512 Credits 4,432
Re msg:

First write a file, you can name it setfile.tmp, with the content “set filename=”. Note that the file must not contain a carriage return character, so you can't use edit to edit it, or if you use edit, then use debug to delete the last two bytes afterward.

Next, change the line @set filename=type date.txt in the program to

@copy setfile.tmp+date.txt setfile.bat >nul
@call setfile.bat
Floor4 iceboy Posted 2003-09-05 00:00
银牌会员 Posts 512 Credits 1,681
Hehe, it's best to use copy /b, otherwise problems are very likely to occur (especially when using EDIT to write setfile.tmp)
Floor5 willsort Posted 2003-10-31 00:00
元老会员 Posts 1,512 Credits 4,432
Re iceboy:

I don't see what effect /b has on this problem. I only know that it is just meant to avoid mistakenly interpreting and executing certain characters in a binary file according to their uses in the ASCII table.

And in my solution, if the temporary file carries a carriage return character, then whether /b is used or not, the correct result will not be obtained.

Also, isn't copy's default parameter /b rather than /a?
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023