批处理脚本工作32位但不工作64位

时间:2015-06-22 12:08:01

标签: batch-file

我有以下.bat文件,它不能在win7 64位上运行。我希望它也能在win7 64位上运行。请使用healp

@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 :(得分:0)

在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 (@This==@IsBatch) @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);