我想用批處理實(shí)現(xiàn)向s.txt中多次分別導(dǎo)入文本例如:“aaaa","bbbb","cccc","dddd"
實(shí)現(xiàn)s.txt內(nèi)效果如:
aaaabbbbccccdddd
可是echo命令每次導(dǎo)入的時(shí)候會(huì)強(qiáng)制換行,如:
aaaa
bbbb
cccc
dddd
我該怎么實(shí)現(xiàn)我想要的一行效果呢?謝謝!
答案:
echo 做不到,不過(guò)可以執(zhí)行以下語(yǔ)句到達(dá)到目的
代碼如下:
>>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的內(nèi)容將是 aaaabbbbccccdddd
注1:“ >>s.txt”這里是輸出流定向的意思,把輸出流重定到了s.txt文件,“<nul ”則是把輸入流指定成了nul,所以set/p="aaaa"就不用等待用戶輸入了。
其實(shí)把寫文件操作放到后面更容易讓人理解些:set /p="aaaa"<nul>>s.txt
注2:關(guān)于set/p="aaaa"的詳細(xì)內(nèi)容請(qǐng)查看《set命令》
實(shí)例1:
if exist %statFile2% ( >>%statFile2% set/p=,%%i<nul ) else ( >>%statFile2% set/p=%%i<nul )
實(shí)例2 ----(個(gè)人添加)
代碼如下:
@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
應(yīng)用:
代碼如下:
echo off
set csvpath=測(cè)試數(shù)據(jù)
set sqluldr=D:\sqluldr\sqluldr2sdk\sqluldr2
set sqlpath=導(dǎo)出模板
rem set filename=產(chǎn)品行情
rem sqluldr2 gtcustomer/passwd file=%csvpath%\%filename%.csv text=csv field=, sql=exp%filename%.sql log=%csvpath%\%filename%.log
rem
rem set filename=產(chǎn)品行情更新
rem sqluldr2 gtcustomer/passwd file=%csvpath%\%filename%.csv text=csv field=, sql=exp%filename%.sql log=%csvpath%\%filename%.log
set expfpath=百萬(wàn)級(jí)
echo 導(dǎo)出%expfpath%數(shù)據(jù):
for %%i in (%sqlpath%\%expfpath%\exp*.sql) do (
set /p="導(dǎo)出數(shù)據(jù): %%~ni"<nul
%sqluldr% gtcustomer/passwd file=%csvpath%\%expfpath%\%%~ni.csv text=csv field=, sql=%%i log=%csvpath%\%expfpath%\%%~ni.log
echo ............ok.
)
set expfpath=千萬(wàn)級(jí)
echo 導(dǎo)出%expfpath%數(shù)據(jù):
for %%i in (%sqlpath%\%expfpath%\exp*.sql) do (
set /p="導(dǎo)出數(shù)據(jù): %%~ni"<nul
%sqluldr% gtcustomer/passwd file=%csvpath%\%expfpath%\%%~ni.csv text=csv field=, sql=%%i log=%csvpath%\%expfpath%\%%~ni.log
echo ............ok.
)
pause
更多信息請(qǐng)查看IT技術(shù)專欄