ECHO 不换行实现方法

我想用批处理实现向s.txt中多次分别导入文本例如:“aaaa","bbbb","cccc","dddd"
实现s.txt内效果如:
aaaabbbbccccdddd
可是echo命令每次导入的时候会强制换行,如:
aaaa
bbbb
cccc
dddd
我该怎么实现我想要的一行效果呢?谢谢!

答案:

echo 做不到,不过可以执行以下语句到达到目的


>>s.txt set /p="aaaa" <nul 

>>s.txt set /p="bbbb" <nul 

>>s.txt set /p="cccc" <nul 

>>s.txt set /p="dddd" <nul

s.txt的内容将是 aaaabbbbccccdddd
注1:“ >>s.txt”这里是输出流定向的意思,把输出流重定到了s.txt文件,“<nul ”则是把输入流指定成了nul,所以set/p="aaaa"就不用等待用户输入了。
其实把写文件操作放到后面更容易让人理解些:set /p="aaaa"<nul>>s.txt

注2:关于set/p="aaaa"的详细内容请查看《set命令》

实例1:

if exist %statFile2% ( >>%statFile2% set/p=,%%i<nul ) else ( >>%statFile2% set/p=%%i<nul )

实例2 ----(个人添加)


@echo off

del b.txt

del c.txt

del d.txt

if exist "%cd%\zhI386" rd /s /q "%cd%\zhI386"

md zhI386

::for /r "%cd%\eni386\" %%i in (*) do (echo %%i>>b.txt)

for /f %%i in ('dir /b %cd%\eni386\') do (

echo %%i>>c.txt

if exist "%cd%\zhall\i386\%%i" (copy "%cd%\zhall\i386\%%i" "%cd%\zhI386\"

) else (>>d.txt set /p="zhall\i386\%%i"<nul&echo ----Not exist>>d.txt)

)

windows批处理之六-echo输出不换行
完整案例:
Code:


@echo off

set /p="hello "<nul

set /p="world "<nul

echo again

echo new line

Result:
hello world again
new line

应用:


echo off

set csvpath=测试数据

set sqluldr=D:\sqluldr\sqluldr2sdk\sqluldr2

set sqlpath=导出模板

rem set filename=产品行情

rem sqluldr2 gtcustomer/passwd file=%csvpath%\%filename%.csv text=csv field=, sql=exp%filename%.sql log=%csvpath%\%filename%.log

rem 

rem set filename=产品行情更新

rem sqluldr2 gtcustomer/passwd file=%csvpath%\%filename%.csv text=csv field=, sql=exp%filename%.sql log=%csvpath%\%filename%.log

set expfpath=百万级 echo 导出%expfpath%数据: for %%i in (%sqlpath%\%expfpath%\exp*.sql) do ( set /p="导出数据: %%~ni"<nul %sqluldr% gtcustomer/passwd file=%csvpath%\%expfpath%\%%~ni.csv text=csv field=, sql=%%i log=%csvpath%\%expfpath%\%%~ni.log echo ............ok. ) set expfpath=千万级 echo 导出%expfpath%数据: for %%i in (%sqlpath%\%expfpath%\exp*.sql) do ( set /p="导出数据: %%~ni"<nul %sqluldr% gtcustomer/passwd file=%csvpath%\%expfpath%\%%~ni.csv text=csv field=, sql=%%i log=%csvpath%\%expfpath%\%%~ni.log echo ............ok. ) pause