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

发布于 2024-12-26 20:26:35 字数 1372 浏览 2 评论 0原文

在我编写的 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

In a DOS script that I wrote, I am unable to figure out what causes this error that I get:

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

Here is the script. Any help would be greatly appreciated. I tried to ask for help on the DosTips forum but I am getting no answer. :

@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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡紫姑娘! 2025-01-02 20:26:35

删除FIND和TYPE的.EXE

您不需要TYPE。您可以这样做:

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

如果FIND破坏了您的结果(不使用TYPE),那么考虑使用FINDSTR代替并使用'DELIMS =:' 而不是 'DELIMS=]'

如果我的假设正确,即以下内容有帮助,请查看 'MORE +nnn ' 命令(注意'+nnn' 从文件中的特定位置输出行)。

为什么不直接将“SETLOCAL ENABLE.. 等”放在代码顶部呢?

如果你解释一下你想要尝试什么,那么我可能可以更好地提供帮助。

只是一些想法:)

Remove the .EXE of FIND and TYPE

You don't need TYPE. You can do just this:

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

If FIND spoils your results (by not using TYPE) then consider using FINDSTR instead and use 'DELIMS=:' instead of 'DELIMS=]'

If I'm right my assumption that the following is helpful, take a look at the 'MORE +nnn' command (note the '+nnn' which outputs lines from a specific location in the file).

Why not just place your 'SETLOCAL ENABLE.. etc' at the top of your code?

If you explain what it is you're trying to attempt, then I might be in a better position to help.

Just a few thoughts :)

ぃ弥猫深巷。 2025-01-02 20:26:35

这是在 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

Here is the working code after getting some help from 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文