中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-18 09:46
47,814 topics / 349,907 posts / today 0 new / 48,259 members
DOS批处理 & 脚本技术(批处理室) » (resolved) How to use a batch file to write ">nul" into a file
Printable Version  2,082 / 7
Floor1 AAAAAAA Posted 2002-10-28 00:00
初级用户 Posts 1 Credits 105
I want to create a batch file that can do writing, and write characters like ">""nul" into AUTOEXEC.BAT

For example, I want to write del 123.456>nul into AUTOEXEC.BAT
But I found that when I write echo del 123.456>nul>autoexec.bat
what gets written into autoexec is only del 123.456
and the following ">nul" is gone. What's going on?

How can I use a batch file to write characters like ">nul" into another file?
Thanks!!!!

---------- Edited by willsort ----------
Original title changed to: Batch file question
---------- Edited by willsort ----------


[ Last edited by willsort on 2005-10-14 at 13:41 ]
Floor2 kickout Posted 2002-10-28 00:00
高级用户 Posts 135 Credits 667
Man, can't you just honestly use edit to edit the batch file? If you use edit you won't have this headache. Because >NUL is also a special use of the redirection operator under DOS, DOS won't know that this is a character you want to write rather than a redirection operator. In fact DOS will treat it as a redirection operator, and thus interpret it as the command being executed directly. Naturally it won't be treated as characters and redirected into autoexec.bat anymore.
Floor3 Wengier Posted 2002-10-28 00:00
系统支持 Posts 10,521 Credits 27,736
You can use an ECHO enhancement tool to accomplish this. It can be found in the site's "script tools":
http://www.cn-dos.net/newdos/doswaren.html
Floor4 okghost Posted 2002-12-01 00:00
初级用户 Posts 14 Credits 140
You did that on purpose, right!
Floor5 willsort Posted 2003-11-15 00:00
元老会员 Posts 1,512 Credits 4,432
Re AAAAAAA:

A simple method, suitable for DOS6.22:

%comspec% /c prompt del 123.456$gnul>autoexec.bat

Similar input includes:

$l less-than sign
$p pipe symbol

[ Last edited by willsort on 2005-10-14 at 13:39 ]
Floor6 龙王 Posted 2003-11-18 00:00
银牌会员 Posts 334 Credits 1,186
Write it like this

Overwrite autoexec.bat
echo del 123.456 >autoexec.bat

Append del 123.456 to the end of autoexec.bat
echo del 123.456 >>autoexec.bat
Floor7 electronixtar Posted 2006-06-28 14:31
铂金会员 Posts 2,672 Credits 7,493
Use echo ^>nul >somebat.bat
Floor8 flysp Posted 2006-06-30 09:19
中级用户 Posts 41 Credits 207
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023