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-07 08:38
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Question: how to save the result of executing a command into a variable View 956 Replies 5
Original Poster Posted 2007-10-16 13:38 ·  新加坡 Verizon通讯公司UUNet互联点
初级用户
Credits 98
Posts 34
Joined 2007-10-16 12:24
18-year member
UID 99881
Gender Male
Status Offline
For example:
save the result of the hostname command into the hn variable..
set hn=`hostname` under XP,, this doesn't work
Floor 2 Posted 2007-10-16 17:56 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Floor 3 Posted 2007-10-16 18:10 ·  中国 北京 海淀区 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
Seems like someone asked this before.
Floor 4 Posted 2007-10-17 02:30 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Hehe, OP, have you been using Shell too much?
Floor 5 Posted 2008-01-22 00:19 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
Why not use the for command to get it directly? I feel like using the pipe symbol should work, but my tests never succeed.
Assign the result of find /c /v "" test.txt
to the variable line, using
set line=|echo|find /c /v "" test.txt
why doesn't it work?
Floor 6 Posted 2008-01-22 10:25 ·  中国 北京 海淀区 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
Did the poster above try it?
Forum Jump: