Dos批处理脚本错误?处理时出错:.exe

时间:2012-01-13 07:40:56

标签: batch-file dos properties-file

在我写的DOS脚本中,我无法找出导致此错误的原因:

The system cannot find the file specified.
Error occurred while processing: .exe.

这是脚本。任何帮助将不胜感激。我试图在DosTips论坛上寻求帮助,但我没有得到答案。 :

@echo off
:: script to edit property files
CALL :PROPEDIT # Key4 Value446 test.properties    
GOTO :END    
:PROPEDIT [#] PropKey PropVal File
IF "%~1"=="#" (
  :: Passing a first argument of "#" will disable the line while editing
  SET "_PREFIX=#"
  SHIFT
)
IF NOT "%~4"=="" (
  ECHO Too many arguments.
  EXIT /B 1
)  
IF "%~3"=="" (
  ECHO PROPEDIT: Function requires 3 args: [#] PropKey PropVal File
  EXIT /B 1
) ELSE (
  SET "_PROPKEY=%~1"
  SET "_PROPVAL=%~2"
  SET "_FILE=%~3"
)
MOVE /Y "%_FILE%" "%_FILE%.bak">nul
FOR /F "USEBACKQ tokens=*" %%A IN (`TYPE "%_FILE%.bak" ^|FINDSTR /N /I "%_PROPKEY%="`) DO (
  SET LINE=%%A
)
FOR /F "tokens=1,2* delims=:" %%S IN ("%LINE%") DO SET LINE=%%S
SET /A COUNT=1
FOR /F "USEBACKQ delims=" %%A IN (`TYPE "%_FILE%.bak" ^|FIND /V /N ""`) DO (
  SET "LN=%%A"
  SETLOCAL ENABLEDELAYEDEXPANSION
  SET "LN=!LN:*]=!"
  IF "!COUNT!" NEQ "%LINE%" (
      ECHO(!LN!>>%_FILE%
  ) ELSE (
      ECHO %_PREFIX%%_PROPKEY%=%_PROPVAL%>>%_FILE%
      ECHO Updated '%_FILE%' with value '%_PREFIX%%_PROPKEY%=%_PROPVAL%'.
  )
  ENDLOCAL
  SET /A COUNT+=1
)
EXIT /B 0
:END
ECHO --- Finished Test ---
pause

2 个答案:

答案 0 :(得分:3)

删除FIND和TYPE的.EXE

您不需要 TYPE 。你可以做到这一点:

FOR /F "tokens=*" %%A IN (`FIND /N /I "%_PROPKEY%=" "%_FILE%.bak"`) DO (

如果 FIND 破坏了您的搜索结果(不使用 TYPE ),请考虑使用 FINDSTR ,然后使用' DELIMS =:< / strong>'而不是' DELIMS =] '

如果我认为以下内容有用,请查看“ MORE + nnn ”命令(请注意“ + nnn ”输出来自文件中特定位置的行。)

为什么不在代码顶部放置“ SETLOCAL ENABLE .. 等”?

如果你解释一下你试图尝试的是什么,那么我可能会更好地帮助你。

只是一些想法:)

答案 1 :(得分:0)

这是Paul Tomasi得到一些帮助后的工作代码:

@echo off
SETLOCAL DISABLEDELAYEDEXPANSION
CALL :PROPEDIT # Key4 Value446 test.properties
GOTO :END
:PROPEDIT [#] PropKey PropVal File
IF "%~1"=="#" (
  :: Passing a first argument of "#" will disable the line while editing
  SET "_PREFIX=#"
  SHIFT
)
IF NOT "%~4"=="" (
  ECHO Too many arguments.
  EXIT /B 1
)  
IF "%~3"=="" (
  ECHO PROPEDIT: Function requires 3 args: [#] PropKey PropVal File
  EXIT /B 1
) ELSE (
  SET "_PROPKEY=%~1"
  SET "_PROPVAL=%~2"
  SET "_FILE=%~3"
)
MOVE /Y "%_FILE%" "%_FILE%.bak">nul
FOR /F "USEBACKQ tokens=*" %%A IN (`TYPE "%_FILE%.bak" ^|FINDSTR /N /I "%_PROPKEY%="`) DO (
  SET LINE=%%A
)
FOR /F "tokens=1,2* delims=:" %%S IN ("%LINE%") DO SET LINE=%%S
SET /A COUNT=1
FOR /F "USEBACKQ delims=" %%A IN (`TYPE "%_FILE%.bak" ^|FIND /V /N ""`) DO (
  SET "LN=%%A"
  SETLOCAL ENABLEDELAYEDEXPANSION
  SET "LN=!LN:*]=!"
  IF "!COUNT!" NEQ "%LINE%" (
      ECHO(!LN!>>%_FILE%
  ) ELSE (
      ECHO %_PREFIX%%_PROPKEY%=%_PROPVAL%>>%_FILE%
      ECHO Updated '%_FILE%' with value '%_PREFIX%%_PROPKEY%=%_PROPVAL%'.
  )
  SETLOCAL DISABLEDELAYEDEXPANSION
  SET /A COUNT+=1
)
EXIT /B 0
:END
ECHO --- Finished Test ---
pause