中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-06-14 14:51
楼 主 关于输出换行的问题 发表于 2008-09-18 17:19 ·  中国 广东 深圳 电信
初级用户
★★
积分 185
发帖 88
注册 2008-05-12 18:46
UID 118511
性别 男
状态 离线
现在我想用ECHO命令将相关字符写入一个文本文件后,发现每一条命令输完后就会换行,示例如下:
ECHO 123 >>1.TXT
ECHO ABC >>1.TXT
此时文本中显示的结果为下:
123
ABC
而我想要的是123ABC,最好是123 ABC(中间多一个空格),本来用
set /p =123<nul >>1.txt
set /p =ABC<nul >>1.txt
在XP下可以完成,但在纯DOS下时就不行,不知哪位高手能指点一下,也可发邮件给我:zhoubin-01@tom.com ,在此不胜感谢!!!!!
2 发表于 2008-09-18 17:22 ·  中国 江苏 苏州 电信
银牌会员
★★★
积分 1,608
发帖 780
注册 2007-10-07 10:19
UID 99089
性别 男
状态 离线
echo 123^
abc
3 发表于 2008-09-18 20:08 ·  中国 广东 深圳 电信
初级用户
★★
积分 185
发帖 88
注册 2008-05-12 18:46
UID 118511
性别 男
状态 离线
谢谢楼上的,我说的是分别执行两个命令,不是一次执行完!不知有没有高手指导一下啊!
4 发表于 2008-09-19 00:51 ·  中国 上海 杨浦区 电信
金牌会员
★★★★
积分 4,639
发帖 2,239
注册 2005-01-30 00:00
UID 35785
性别 男
状态 离线
你先把你发的多余的帖子删除我再回答你的问题,保证100%解决。
5 发表于 2008-09-19 07:59 ·  中国 广东 深圳 电信
初级用户
★★
积分 185
发帖 88
注册 2008-05-12 18:46
UID 118511
性别 男
状态 离线
OK,俺们删除!在线等侯!...
6 发表于 2008-09-19 08:10 ·  中国 广东 深圳 电信
初级用户
★★
积分 185
发帖 88
注册 2008-05-12 18:46
UID 118511
性别 男
状态 离线
删除了,能回答了吗?

[ Last edited by hhasee on 2008-9-19 at 08:20 AM ]
7 发表于 2008-09-19 12:43 ·  中国 上海 杨浦区 电信
金牌会员
★★★★
积分 4,639
发帖 2,239
注册 2005-01-30 00:00
UID 35785
性别 男
状态 离线
可以用 4DOS 的 echos 命令

4DOS Help Topic: ECHOS


Purpose: Display a message without a trailing carriage return and line
feed.

Format: ECHOS message

message: Text to display.

See also: ECHO, ECHOERR, ECHOSERR, SCREEN, SCRPUT, TEXT, and VSCRPUT.

Usage

ECHOS is useful for text output when you don't want to add a carriage return
and line feed at the end of the line. For example, you can use ECHOS when
you need to redirect control sequences to your printer; this example sends
the sequence Esc P to the printer on LPT1:

c:\> echos eP > lpt1:

To include the command separator character or the redirection and piping
symbols in an ECHOS message, enclose them in quotes (see Argument
Quoting) or precede them with the escape character.

If you want to embed a carriage return or other control character in the
message, you can use the @CHAR function or an escape sequence. For
instance, you might wish to print a carriage return at the start of your
message to move the cursor to the start of the line, so you can overwrite
text already on the screen. Use @CHAR or %=r to print a carriage
return:

do i = 100 to 0 by -1
echos %=r%i` `
delay /m 1
enddo

ECHOS does not translate or modify the message text. For example, carriage
return characters are not translated to CR/LF pairs. ECHOS sends only the
characters you specify. The only character you cannot put into an ECHOS
message is the NUL character (ASCII 0).

To include the command separator character or the redirection and piping
symbols in an ECHOS message, enclose them in quotes (see Argument
Quoting) or precede them with the escape character.

Trailing spaces in the message are normally ignored. To display trailing
spaces, enclose them in back-quotes, as in the example above.

ECHOS can not be used to change or display the current command-echo state.
Use ECHO to control echoing of commands in a batch file or at the prompt.
8 发表于 2008-09-19 17:39 ·  中国 广东 深圳 电信
初级用户
★★
积分 185
发帖 88
注册 2008-05-12 18:46
UID 118511
性别 男
状态 离线
不是很明白,能不能加点注解????
9 发表于 2008-09-19 17:56 ·  中国 上海 杨浦区 电信
金牌会员
★★★★
积分 4,639
发帖 2,239
注册 2005-01-30 00:00
UID 35785
性别 男
状态 离线
如果你一下子看不明白的话不必仔细全部看一遍,你只要记着这样用:
echos 123
echos ABC
得到的结果就是 123ABC 就可以了。
10 发表于 2008-09-20 09:46 ·  中国 四川 遂宁 电信
初级用户
★★
积分 121
发帖 54
注册 2008-01-10 19:13
UID 108238
性别 男
状态 离线
可不可以换种思维?

set 2s=abc
echo 123%2s% >1.txt

提前转一步。
不懂就要虛心請教!
11 发表于 2008-09-20 10:29 ·  中国 河北 保定 移动
铂金会员
★★★★
网络独行侠
积分 6,962
发帖 2,753
注册 2003-04-16 00:00
UID 1565
性别 男
来自 河北保定
状态 离线
一般来说,微软自己提供的echo命令,显示结果后面是紧跟着回车和换行的。所以,要实现楼主的需要,一般都要借助第三方工具,DosForever兄使用了4DOS,我印象中还有Horst的qecho(Quote echo),例如:

QECHO "something" CR LF
相当于: ECHO something

所以,以顶楼的情况来说,你可以使用:
qecho "123" >> 1.txt
qecho " ABC" CR LF >> 1.txt

d:\>qecho '123' >1.txt

d:\>qecho ' ABC' >> 1.txt

d:\>type 1.txt
123 ABC
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
12 发表于 2008-09-26 10:09 ·  中国 广东 深圳 电信
初级用户
★★
积分 185
发帖 88
注册 2008-05-12 18:46
UID 118511
性别 男
状态 离线
都是高手啊,收获不小,十分感谢!!!
论坛跳转: