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-12 16:31
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » Who knows the usage of the redirection commands < and << in Dos? View 2,125 Replies 9
Original Poster Posted 2006-11-24 09:51 ·  中国 陕西 西安 电信
新手上路
Credits 6
Posts 2
Joined 2006-11-24 08:26
19-year member
UID 71558
Gender Male
Status Offline
Although the materials all say that it can read things from files, there are no examples. Now I have a text file with only one number. I want to read it out and assign it to a variable. How to do it? I tried set var=<a.txt, which doesn't work. Hope to get some ideas or materials!
Floor 2 Posted 2008-09-19 14:17 ·  中国 北京 联通
初级用户
Credits 36
Posts 19
Joined 2007-12-29 10:53
18-year member
UID 107102
Gender Male
Status Offline
Help to top up. I also want to know how to do it. Most of the things in the forum are >.
Floor 3 Posted 2008-11-27 16:15 ·  中国 上海 黄浦区 电信
初级用户
★★
Credits 35
Posts 62
Joined 2008-10-12 21:46
17-year member
UID 128197
Gender Male
Status Offline
">" and ">>" are both output redirections. However, ">>" appends the content to be output to the end of the document. For example:

@echo off
dir > d:\1.txt
pause

@echo off
dir >> d:\1.txt
pause

You can see the difference by having a look.
Floor 4 Posted 2008-11-27 17:22 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
It is suggested to ask questions in the Batch Processing Room
Floor 5 Posted 2008-11-27 19:59 ·  中国 上海 杨浦区 电信
金牌会员
★★★★
Credits 4,639
Posts 2,239
Joined 2005-01-30 00:00
21-year member
UID 35785
Gender Male
Status Offline
Hehe, I don't think this is only related to batch processing. Redirecting command lines can also be used.
Floor 6 Posted 2008-11-28 21:39 ·  中国 北京 联通
高级用户
★★
Credits 652
Posts 193
Joined 2005-09-25 00:00
20-year member
UID 42822
Status Offline
< is input redirection, providing the internal response of the software. The content of dir.txt has only one byte which is D. For example, xcopy adir bdir < dir.txt. When prompted "Does 2 specify a file name or directory name on the target (F = File, D = directory)", the answer "D" will automatically become the answer and the copy continues.
ディスケット オペレーティン グシステム
Floor 7 Posted 2008-11-28 21:43 ·  中国 北京 联通
高级用户
★★
Credits 652
Posts 193
Joined 2005-09-25 00:00
20-year member
UID 42822
Status Offline
Originally posted by wwmmc at 2008-11-27 16:15:
">" ">>"
Both are output redirections
However, ">>" appends the content to be output to the end of the document
For example:
@echo off
dir > d:\1.txt
pause

@echo off
...


There are several other uses for the output redirection ">", such as
dir > PRN
This sends the content output by dir directly to the printer (only printers using the LPT port)
And the following
pkunzip aa.zip c:\tools > nul
This means no decompression information is output during the decompression of aa.zip
ディスケット オペレーティン グシステム
Floor 8 Posted 2008-11-28 21:56 ·  中国 黑龙江 大兴安岭地区 联通
初级用户
★★
Credits 190
Posts 101
Joined 2008-11-23 14:58
17-year member
UID 131841
Gender Male
Status Offline
">" is output; ">>" is append; "<" is input.
Floor 9 Posted 2009-02-10 13:45 ·  中国 天津 电信
社区乞丐
Credits -46
Posts 25
Joined 2009-02-09 13:16
17-year member
UID 138388
Gender Male
From 内蒙
Status Offline
Hope there are some experts to give a few examples
Floor 10 Posted 2009-02-12 22:35 ·  中国 甘肃 张掖 电信
初级用户
Credits 47
Posts 27
Joined 2008-06-23 22:44
18-year member
UID 120749
Gender Male
From 甘肃. 武威
Status Offline
Take it back and Google it a bit!
好好学习,
天天向上。
Forum Jump: