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 07:58
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to directly assign the output result of a DOS command to a variable in a batch script View 1,766 Replies 8
Original Poster Posted 2006-11-30 00:57 ·  中国 广东 广州 越秀区 电信
新手上路
Credits 8
Posts 2
Joined 2006-11-28 22:43
19-year member
UID 72019
Gender Male
Status Offline
As the title says
Floor 2 Posted 2006-11-30 05:54 ·  中国 河南 郑州 电信
中级用户
★★
Credits 439
Posts 170
Joined 2006-01-09 20:29
20-year member
UID 48707
Status Offline
for %%i in (命令) set %%i
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
jgc +2 2007-01-06 05:55
qzwqzw -5 2007-01-06 06:27
Floor 3 Posted 2006-11-30 06:15 ·  中国 北京 朝阳区 联通
高级用户
★★
朦胧的世界
Credits 579
Posts 218
Joined 2006-10-24 04:29
19-year member
UID 67972
Status Offline
Put single quotes around the command, like ''command''

认识自己,降伏自己,改变自己
,才能改变别人!
Floor 4 Posted 2006-12-11 01:06 ·  中国 河南 洛阳 联通
初级用户
Credits 38
Posts 19
Joined 2006-10-02 03:51
19-year member
UID 64281
Status Offline
Please provide the Chinese content that needs to be translated.
Floor 5 Posted 2006-12-19 10:13 ·  中国 山西 长治 联通
初级用户
Credits 23
Posts 11
Joined 2006-12-19 09:34
19-year member
UID 73946
Gender Male
Status Offline
Experts, give a detailed explanation!
Floor 6 Posted 2006-12-19 22:54 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
Just find the output of the 'command' and assign the output to the variable %i
Floor 7 Posted 2007-01-06 06:18 ·  中国 上海 东方有线
初级用户
Credits 153
Posts 20
Joined 2005-02-02 00:00
21-year member
UID 35889
Gender Male
Status Offline
In addition, don't forget do and parameter /f.
Revised to:
for /f %%i in ('command') do set %%i
Floor 8 Posted 2007-01-06 07:16 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
  Revise again:

FOR /F %variable IN ('command') DO command
[ Last edited by lxmxn on 2007-1-5 at 06:17 PM ]
Floor 9 Posted 2008-01-22 00:22 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
Why do you all use for? Don't you think the code is long?
Forum Jump: