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-04 09:47
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How can I assign the output of type test.txt to a variable? View 792 Replies 4
Original Poster Posted 2007-04-23 07:18 ·  中国 广东 珠海 电信
初级用户
潜水&&搜索
Credits 70
Posts 28
Joined 2007-04-22 14:36
19-year member
UID 86095
Gender Male
Status Offline
How can I assign the output of type test.txt to a variable?
There is only one constantly changing number in the test.txt file.
Floor 2 Posted 2007-04-23 07:21 ·  中国 广东 广州 海珠区 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
for /f "tokens=* " %%i in (test.txt) do echo %%i


Just change that last echo %%i
however you like :)
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
Dana +1 2007-04-23 10:00
知,不觉多。不知,乃求知
Floor 3 Posted 2007-04-23 07:22 ·  中国 浙江 杭州 电信
银牌会员
★★★
Credits 2,000
Posts 621
Joined 2007-01-01 00:00
19-year member
UID 75212
Gender Male
Status Offline
Under cmd

for /f "delims=" %a in (text.txt) do set "a=%a"
Floor 4 Posted 2007-04-23 08:31 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
If text.txt contains only one line, then you can do it like this:

set /p str=<test.txt
echo %str%
Floor 5 Posted 2007-04-23 10:01 ·  中国 广东 珠海 电信
初级用户
潜水&amp;&amp;搜索
Credits 70
Posts 28
Joined 2007-04-22 14:36
19-year member
UID 86095
Gender Male
Status Offline
Many thanks, everyone.....
Forum Jump: