2015-06-22 41 views
0

我有以下未Win7上工作.bat文件64個bit.I希望它的64位also.Please healp批處理腳本工作在32位,但不工作的64位

@echo off 
setlocal disableDelayedExpansion 


set x=^ 


rem for /f %%? in ('2^>nul ^(^< output.md find /c /v "" ^)') do set "$end=%%?" 

rem echo.linefeeds[%$end%] 


< output.md (

    for /l %%i in (1, 1, 100) do set "b=" &set /p "b=" &(

     setlocal enabledelayedexpansion 
     (set /p y=!b!!x! <nul) 
     endlocal 
    ) 
) > out.md 
+1

它不起作用?你得到的和你期望的有什麼區別? –

+0

這段代碼基本上是將CRLF(DOS格式)轉換爲LF(UNIX格式)。它在32位win XP下工作完全正常,但在每行開頭的win7 64位製表符正在消失。我不希望發生這種情況。 –

回答

0

Win7上運行在Windows Vista中,set /p命令在輸出提示開始時刪除空格和製表符。您不能使用在Windows這個方法7

對於純一批解決方案,您可以使用

@echo off 
    setlocal enableextensions disabledelayedexpansion 

    rem Configure files 
    set "inputFile=input.txt" 
    set "outputFile=output.txt" 

    rem A temp file is needed 
    set "tempFile=%temp%\%~nx0.%random%%random%%random%.tmp" 
    rem Retrieve a line feed into a variabla 
    set LF=^ 



    rem Retrieve a SUB (0x1A) character into a variable 
    copy nul "%tempFile%" /a >nul 
    for /f "usebackq" %%a in ("%tempFile%") do set "SUB=%%a" 

    rem For each line inside input file 
    (for /f "usebackq delims=" %%a in ("%inputFile%") do (
     rem Retrieve the line contents 
     set "line=%%a" 

     rem Output the line, a line feed a SUB and the CRLF (from echo) to a file 
     setlocal enabledelayedexpansion 
     >"%tempFile%" (echo(!line!!LF!!sub!) 
     endlocal 

     rem From the generated file, copy everything up to the SUB character 
     rem The SUB and everything after it will be discarded 
     >nul copy "%tempFile%" /a "%tempFile%2" /b 

     rem Output the generated line 
     type "%tempFile%2" 

    )) > "%outputFile%" 

    rem Remove temporary files used 
    del /q "%tempFile%*" 

但更高效的解決方案將使用在操作系統中可用的本地腳本引擎。

這是一種混合CMD/JScript的批處理文件(帶有.cmd擴展名保存)被用作

cr2lf.cmd <inputfile> outputFile 

該代碼將剛剛讀取標準輸入和對於每個輸入線路輸出的同一行,接着用線飼料字符

@if (@[email protected]) @then 
@echo off 
rem **** batch zone ********************************************************* 

    setlocal enableextensions disabledelayedexpansion 
    call :runInnerScript 
    exit /b 

:runInnerScript 
    cscript //E:JScript "%~f0" 
    goto :eof 

@end 
// **** Javascript zone ***************************************************** 

    while (!WScript.StdIn.AtEndOfStream){ 
     WScript.StdOut.Write(WScript.StdIn.ReadLine() + '\n'); 
    }; 
    // All done. Exit 
    WScript.Quit(0); 
+0

謝謝你的迴應。但我在我的批處理腳本中使用了dos2unix工具來解決我的工作問題。 –

相關問題