echo no newline 转载:http://stackoverflow.com/questions/7105433/windows-batch-echo-without-new-line

Using: echo | set /p= or <NUL set /p= will both work to suppress the newline.

However, this can be very dangerous when writing more advanced scripts when checking the ERRORLEVEL becomes important as setting set /p= without specifying a variable name will set the ERRORLEVEL to 1.

A better approach would be to just use a dummy variable name like so:
echo | set /p dummyName=Hello World

This will produce exactly what you want without any sneaky stuff going on in the background as I had to find out the hard way, but this only works with the piped version; <NUL set /p dummyName=Hello will still raise the ERRORLEVEL to 1.

share|improve this answer
 
    
"echo | /p dummyName=Hello World" outputs "'/p' is not recognized as an internal or external command, operable program or batch file.", at least from the command line (even with a pause in a BAT file, the output disappeared too fast). –  Peter Mortensen Aug 9 '12 at 12:07 
    
Note: Author has edited answer to correct the missing part of the command, per Peter Mortensen's comment–  user66001 Jun 3 '13 at 18:04

posted on 2014-03-21 13:49  wensky  阅读(467)  评论(0)    收藏  举报

导航