中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟
中国DOS联盟论坛
现在时间是 2026-08-11 01:45
47,811 主题排行 / 349,897 发帖 / 今日 0 篇 / 48,256 会员排行
DOS疑难解答 & 问题讨论 (解答室) » 关于输出换行的问题
可打印版本  1,328 / 11
第1楼 hhasee 发表于 2008-09-18 17:19
初级用户 发帖 88 积分 185
关于输出换行的问题
现在我想用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楼 huahua0919 发表于 2008-09-18 17:22
银牌会员 发帖 780 积分 1,608
echo 123^
abc
第3楼 hhasee 发表于 2008-09-18 20:08
初级用户 发帖 88 积分 185
谢谢楼上的,我说的是分别执行两个命令,不是一次执行完!不知有没有高手指导一下啊!
第4楼 DOSforever 发表于 2008-09-19 00:51
金牌会员 发帖 2,239 积分 4,639
你先把你发的多余的帖子删除我再回答你的问题,保证100%解决。
第5楼 hhasee 发表于 2008-09-19 07:59
初级用户 发帖 88 积分 185
OK,俺们删除!在线等侯!...
第6楼 hhasee 发表于 2008-09-19 08:10
初级用户 发帖 88 积分 185
删除了,能回答了吗?

[ Last edited by hhasee on 2008-9-19 at 08:20 AM ]
第7楼 DOSforever 发表于 2008-09-19 12:43
金牌会员 发帖 2,239 积分 4,639
可以用 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楼 hhasee 发表于 2008-09-19 17:39
初级用户 发帖 88 积分 185
不是很明白,能不能加点注解????
第9楼 DOSforever 发表于 2008-09-19 17:56
金牌会员 发帖 2,239 积分 4,639
如果你一下子看不明白的话不必仔细全部看一遍,你只要记着这样用:
echos 123
echos ABC
得到的结果就是 123ABC 就可以了。
第10楼 clong 发表于 2008-09-20 09:46
初级用户 发帖 54 积分 121
可不可以换种思维?

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

提前转一步。
第11楼 Climbing 发表于 2008-09-20 10:29
铂金会员 发帖 2,753 积分 6,962 来自 河北保定
一般来说,微软自己提供的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楼 hhasee 发表于 2008-09-26 10:09
初级用户 发帖 88 积分 185
都是高手啊,收获不小,十分感谢!!!
[ 联系联盟系统管理团队 - 中国DOS联盟 - 标准版 ]
Sponsored by ifanr Inc | © 2001–2023