'c:\Program' 不是内部或外部命令,也不是可运行的命令或批处理文件

'c:\Program' is not recognized as an internal or external command, operable command or batch file

成功安装 Oracle SOA Suite 12c 后,我正在尝试安装 RCU。

当我尝试从命令提示符执行 RCU 批处理文件时,出现此错误:

'c:\Program' is not recognized as an internal or external command, operable command or batch file

批处理文件位于以下路径:

C:\Oracle\Middleware\Oracle_Home\oracle_common\bin

这是我的 PATH 环境变量值:

C:\app\gadmin\product.0.0\dbhomeXE\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\PuTTY\;C:\Program Files\SafeNet\Authentication\SAC\x64;C:\Program Files\SafeNet\Authentication\SAC\x32

这在我的 PATHTEXT 环境变量值中:

.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

我正在尝试的批处理文件 运行 :

rcu.bat

@REM Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
@REM Wrapper script to launch Oracle home base rcu script
@echo off
setlocal

SET INTERNAL_SCRIPT=rcu_internal.bat
SET WLS_ORACLE_HOME=C:\Oracle\Middleware\Oracle_Home
SET INTERNAL_SCRIPTPATH=
IF EXIST %WLS_ORACLE_HOME% (
        SET INTERNAL_SCRIPTPATH="%WLS_ORACLE_HOME%\oracle_common\bin"
) ELSE (
        SET INTERNAL_SCRIPTPATH=%~dp0
)
CALL %INTERNAL_SCRIPTPATH%\%INTERNAL_SCRIPT% %*

rcu_internal.bat


@REM Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.

@echo off

setlocal



rem ORACLE_HOME is the parent directory of the "oracle_common\bin" dir where the rcu script is located
SET SCRIPT_PATH=%~dp0
FOR %%i IN ("%SCRIPT_PATH%") DO SET SCRIPT_PATH=%%~fsi

@REM Set the ORACLE_HOME relative to this script...
FOR %%i IN ("%SCRIPT_PATH%\..\..") DO SET ORACLE_HOME=%%~fsi

@set LOG_LOCATION_VAR=
@set LOG_LEVEL_VAR=
@set LOG_NAME_VAR=
@set LOG_FORMATTER_VAR=
@set TIMESTAMP_LOG_DIR_VAR=
@set PRETTY_NAME_VAR=
@set OPERATION1_NAME_VAR=
@set OPERATION2_NAME_VAR=
@set OPERATION1_CMDLINE_VAR=
@set OPERATION2_CMDLINE_VAR=
@set DBMS_OUTPUT_IN_SEPARATE_FILE_VAR=
@set RCU_PRODUCT_NAME_VAR=
@set RCU_TWO_PHASE_VAR=
@set ENABLE_JAVADB_VAR=

@if not "%RCU_TIMESTAMP_LOG_DIR%" == ""  set TIMESTAMP_LOG_DIR_VAR=-DRCU_TIMESTAMP_LOG_DIR=%RCU_TIMESTAMP_LOG_DIR%
@if "%RCU_TIMESTAMP_LOG_DIR%" == ""  set TIMESTAMP_LOG_DIR_VAR=-DRCU_TIMESTAMP_LOG_DIR=true
@if not "%RCU_LOG_LOCATION%" == ""  set LOG_LOCATION_VAR=-DRCU_LOG_LOCATION="%RCU_LOG_LOCATION%"
@if not "%RCU_LOG_LEVEL%" == ""  set LOG_LEVEL_VAR=-DRCU_LOG_LEVEL=%RCU_LOG_LEVEL%
@if "%RCU_LOG_LEVEL%" == ""  set LOG_LEVEL_VAR=-DRCU_LOG_LEVEL=NOTIFICATION
@if not "%RCU_LOG_NAME%" == ""  set LOG_NAME_VAR=-DRCU_LOG_NAME="%RCU_LOG_NAME%"
@if not "%RCU_LOG_FORMATTER%" == ""  set LOG_FORMATTER_VAR=-DRCU_LOG_FORMATTER=%RCU_LOG_FORMATTER%
@if not "%USE_PRETTY_NAMES%" == "" set PRETTY_NAME_VAR=-DUSE_PRETTY_NAMES=%USE_PRETTY_NAMES%
@if not "%RCU_OPERATION1_NAME%" == ""  set OPERATION1_NAME_VAR=-DRCU_OPERATION1_NAME=%RCU_OPERATION1_NAME%
@if not "%RCU_OPERATION2_NAME%" == ""  set OPERATION2_NAME_VAR=-DRCU_OPERATION2_NAME=%RCU_OPERATION2_NAME%
@if not "%RCU_OPERATION1_CMDLINE%" == ""  set OPERATION1_CMDLINE_VAR=-DRCU_OPERATION1_CMDLINE=%RCU_OPERATION1_CMDLINE%
@if not "%RCU_OPERATION2_CMDLINE%" == ""  set OPERATION2_CMDLINE_VAR=-DRCU_OPERATION2_CMDLINE=%RCU_OPERATION2_CMDLINE%
@if not "%RCU_DBMS_OUTPUT_IN_SEPARATE_FILE%" == ""  set DBMS_OUTPUT_IN_SEPARATE_FILE_VAR=-DRCU_DBMS_OUTPUT_IN_SEPARATE_FILE=%RCU_DBMS_OUTPUT_IN_SEPARATE_FILE%
@if not "%RCU_PRODUCT_NAME%" == ""  set RCU_PRODUCT_NAME_VAR=-DRCU_PRODUCT_NAME=%RCU_PRODUCT_NAME%
@if not "%USE_TWO_PHASE_RCU%" == "" set RCU_TWO_PHASE_VAR=-DUSE_TWO_PHASE_RCU=%USE_TWO_PHASE_RCU%
@if not "%ENABLE_JAVADB%" == "" set ENABLE_JAVADB_VAR=-DENABLE_JAVADB=%ENABLE_JAVADB%

@set RCU_ENV_VARS=%LOG_LOCATION_VAR% %LOG_LEVEL_VAR% %LOG_NAME_VAR% %LOG_FORMATTER_VAR% %TIMESTAMP_LOG_DIR_VAR% %PRETTY_NAME_VAR% %OPERATION1_NAME_VAR% %OPERATION2_NAME_VAR% %OPERATION1_CMDLINE_VAR% %OPERATION2_CMDLINE_VAR% %DBMS_OUTPUT_IN_SEPARATE_FILE_VAR% %RCU_PRODUCT_NAME_VAR% %RCU_TWO_PHASE_VAR% %ENABLE_JAVADB_VAR%

@set LAUNCH_MODE=%LAUNCH_MODE%
@set OH=%ORACLE_HOME%
@set RCU_HOME=%ORACLE_HOME%\oracle_common
@set OH_J2EE=%ORACLE_HOME%\j2ee\home

@set JLIB_DIR=%RCU_HOME%\jlib
@set JRE_DIR=%OH%\jdk\jre
@set RCUHELP_FILE=rchlp.jar

IF [%LANG%] == []  (
  FOR /F "tokens=3 delims= " %%G in ('reg query "hklm\system\controlset001\control\nls\language" /v Default') DO (
    IF [%%G] EQU [0407] (
      set RCUHELP_FILE=rchlp_de.jar
    ) ELSE IF [%%G] EQU [040c] (
      set RCUHELP_FILE=rchlp_fr.jar
    ) ELSE IF [%%G] EQU [040a] (
      set RCUHELP_FILE=rchlp_es.jar
    ) ELSE IF [%%G] EQU [0410] (
      set RCUHELP_FILE=rchlp_it.jar
    ) ELSE IF [%%G] EQU [0411] (
      set RCUHELP_FILE=rchlp_ja.jar
    ) ELSE IF [%%G] EQU [0412] (
      set RCUHELP_FILE=rchlp_ko.jar
    ) ELSE IF [%%G] EQU [0416] (
      set RCUHELP_FILE=rchlp_pt_BR.jar
    ) ELSE IF [%%G] EQU [0804] (
      set RCUHELP_FILE=rchlp_zh_CN.jar
    ) ELSE IF [%%G] EQU [0404] (
      set RCUHELP_FILE=rchlp_zh_TW.jar
    )
  )
) ELSE (  
  echo %LANG%|findstr /i "de" >nul:
  if not errorlevel 1 set RCUHELP_FILE=rchlp_de.jar
  echo %LANG%|findstr /i "fr" >nul:
  if not errorlevel 1 set RCUHELP_FILE=rchlp_fr.jar
  echo %LANG%|findstr /i "es" >nul:
  if not errorlevel 1 set RCUHELP_FILE=rchlp_es.jar
  echo %LANG%|findstr /i "it" >nul:
  if not errorlevel 1 set RCUHELP_FILE=rchlp_it.jar
  echo %LANG%|findstr /i "ja" >nul:
  if not errorlevel 1 set RCUHELP_FILE=rchlp_ja.jar
  echo %LANG%|findstr /i "ko" >nul:
  if not errorlevel 1 set RCUHELP_FILE=rchlp_ko.jar
  echo %LANG%|findstr /i "pt_BR" >nul:
  if not errorlevel 1 set RCUHELP_FILE=rchlp_pt_BR.jar
  echo %LANG%|findstr /i "zh_CN" >nul:
  if not errorlevel 1 set RCUHELP_FILE=rchlp_zh_CN.jar
  echo %LANG%|findstr /i "zh_TW" >nul:
  if not errorlevel 1 set RCUHELP_FILE=rchlp_zh_TW.jar
)

@set RCU_CLASSPATH=%JLIB_DIR%\rcu.jar
@set HELPSET_CLASSPATH=%JLIB_DIR%\%RCUHELP_FILE%

@set PATH=%RCU_HOME%\bin;%PATH%

@set CLASSPATH=%RCU_CLASSPATH%;%HELPSET_CLASSPATH%

rem If no parameter passed, RCU should start run as silent mode.

@if  "%JAVA_HOME%" == "" set JAVA_HOME=%JRE_DIR%
@if not "%JAVA_HOME%" == "" if exist %JAVA_HOME%\jre\bin\javaw.exe set JAVA_HOME=%JAVA_HOME%\jre\

if NOT exist "%JAVA_HOME%\bin\java.exe" (
        if exist "%RCU_HOME%\..\oui\bin\getVariable.cmd" (
        @REM INVOKE SCRIPT TO SET THE JAVA_HOME
        CALL %RCU_HOME%\..\oui\bin\getVariable.cmd JAVA_HOME JAVA_HOME
     )
)

if NOT exist "%JAVA_HOME%\bin\java.exe" (
    if exist "%RCU_HOME%\jdk" (
        @REM SET THE JAVA_HOME to oracle_common/jdk
        set JAVA_HOME=%RCU_HOME%\jdk
     )
)

for %%i in ("%JAVA_HOME%") do set JAVA_HOME=%%~fsi

if NOT exist "%JAVA_HOME%\bin\java.exe" (
     echo Unable to locate java at the following location: %JAVA_HOME%\bin\java. Please set the correct value for JAVA_HOME or ORACLE_HOME and try again.
         SET ERRORLEVEL=1
         goto end

)


if "%~1"=="" goto console 
%JAVA_HOME%\bin\java %RCU_JAVA_OPTIONS% -DRCU_HOME=%RCU_HOME% -DSQLPLUS_HOME=%OH% -DORACLE_HOME=%OH% %RCU_ENV_VARS% -DLAUNCH_MODE=%LAUNCH_MODE% -mx128m  -classpath %CLASSPATH% oracle.sysman.assistants.rcu.Rcu -lockSchemas false %*
goto end

:console
%JAVA_HOME%\bin\java -DRCU_HOME=%RCU_HOME% -DSQLPLUS_HOME=%OH% -DORACLE_HOME=%OH% -DRANDOMIZE_PASSWORDS=true %RCU_ENV_VARS% -DLAUNCH_MODE=%LAUNCH_MODE% -mx128m %RCU_JAVA_OPTIONS% -classpath %CLASSPATH% oracle.sysman.assistants.rcu.Rcu

:end
exit /B %ERRORLEVEL%

我建议修改rcu.bat为:

@REM Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
@REM Wrapper script to launch Oracle home base rcu script
@ECHO OFF
SETLOCAL EnableExtensions DisableDelayedExpansion

SET "INTERNAL_SCRIPT=rcu_internal.bat"
SET "WLS_ORACLE_HOME=C:\Oracle\Middleware\Oracle_Home"
SET "INTERNAL_SCRIPTPATH="
IF EXIST "%WLS_ORACLE_HOME%" (
    SET "INTERNAL_SCRIPTPATH=%WLS_ORACLE_HOME%\oracle_common\bin\"
) ELSE (
    SET "INTERNAL_SCRIPTPATH=%~dp0"
)
CALL "%INTERNAL_SCRIPTPATH%%INTERNAL_SCRIPT%" %*

ENDLOCAL

每个引用文件或文件夹的参数字符串都必须用双引号括起来,以确保即使在 file/folder 名称中也能正常工作,不带或带路径包含 space 或这些字符之一 &()[]{}^=;!'+,`~.

表达式 %~dp0 扩展为始终以反斜杠结尾的批处理文件的完整限定路径。因此,%~dp0 不应像此处通过环境变量 INTERNAL_SCRIPTPATH 那样直接或间接连接,并带有一个带有 file/folder 名称的附加反斜杠。否则会导致扩展路径中的 \,Windows 需要更正为单个 \,然后才能将 file/folder 名称和路径传递到文件系统。这就是在 %WLS_ORACLE_HOME%\oracle_common\bin 末尾附加反斜杠并在命令 CALL.

的参数字符串中删除反斜杠的原因

命令SETLOCAL的使用只会导致将当前目录路径压入堆栈,并将指针指向当前环境变量列表。命令扩展的状态和延迟环境变量扩展的状态在仅使用不带任何参数的 SETLOCAL 时不会改变。因此执行环境将在批处理文件之外定义。这是不好的。批处理文件不应该依赖于其他应用程序或批处理文件设置为执行环境。此批处理文件需要启用命令扩展并禁用延迟环境变量扩展才能独立于批处理文件的完整路径工作。因此命令 SETLOCAL 与两个可选参数一起使用来定义所需的执行环境。请阅读 以获取有关命令 SETLOCALENDLOCAL.

的详细信息

我建议阅读我在 and on Why is no string output with 'echo %var%' after using 'set var = text' on command line? 上的回答,以了解为什么最好将命令 SET 的参数字符串 variable=value 括在双引号中第一个 " 留给变量名,而不是变量值的开头。这有很大的不同。

SET INTERNAL_SCRIPTPATH="%WLS_ORACLE_HOME%\oracle_common\bin"的用法在扩展命令行CALL %INTERNAL_SCRIPTPATH%\%INTERNAL_SCRIPT% %*上的结果:

CALL "C:\Oracle\Middleware\Oracle_Home\oracle_common\bin"\rcu_internal.bat %*

命令 CALL 的第一个参数引用不正确。第二个 " 应该在 .bat 之后的参数字符串的末尾,而不是在中间的某个地方。上面建议的代码导致命令 CALL.

的第一个参数字符串始终 100% 正确

我建议 rcu_internal.bat 使用以下代码:

@rem Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
@echo off
setlocal EnableExtensions DisableDelayedExpansion

@rem ORACLE_HOME is the parent directory of the "oracle_common\bin"
@rem directory where the rcu script is located.
@rem Set the ORACLE_HOME relative to this script...
for %%I in ("%~dp0..\..") do set "ORACLE_HOME=%%~fI"

@rem Make sure the ORACLE_HOME path does not end with a
@rem backslash even on being the root directory of a drive.
if "%ORACLE_HOME:~-1%" == "\" set "ORACLE_HOME=%ORACLE_HOME:~0,-1%"

@set "LOG_LOCATION_VAR="
@set "LOG_LEVEL_VAR="
@set "LOG_NAME_VAR="
@set "LOG_FORMATTER_VAR="
@set "TIMESTAMP_LOG_DIR_VAR="
@set "PRETTY_NAME_VAR="
@set "OPERATION1_NAME_VAR="
@set "OPERATION2_NAME_VAR="
@set "OPERATION1_CMDLINE_VAR="
@set "OPERATION2_CMDLINE_VAR="
@set "DBMS_OUTPUT_IN_SEPARATE_FILE_VAR="
@set "RCU_PRODUCT_NAME_VAR="
@set "RCU_TWO_PHASE_VAR="
@set "ENABLE_JAVADB_VAR="

@if defined RCU_TIMESTAMP_LOG_DIR set "TIMESTAMP_LOG_DIR_VAR=-DRCU_TIMESTAMP_LOG_DIR=%RCU_TIMESTAMP_LOG_DIR%"
@if not defined RCU_TIMESTAMP_LOG_DIR set "TIMESTAMP_LOG_DIR_VAR=-DRCU_TIMESTAMP_LOG_DIR=true"
@if defined RCU_LOG_LOCATION set "LOG_LOCATION_VAR=-DRCU_LOG_LOCATION="%RCU_LOG_LOCATION%" "
@if defined RCU_LOG_LEVEL set "LOG_LEVEL_VAR=-DRCU_LOG_LEVEL=%RCU_LOG_LEVEL%"
@if not defined RCU_LOG_LEVEL set "LOG_LEVEL_VAR=-DRCU_LOG_LEVEL=NOTIFICATION"
@if defined RCU_LOG_NAME set "LOG_NAME_VAR= -DRCU_LOG_NAME="%RCU_LOG_NAME%""
@if defined CU_LOG_FORMATTER set "LOG_FORMATTER_VAR= -DRCU_LOG_FORMATTER=%RCU_LOG_FORMATTER%"
@if defined USE_PRETTY_NAMES set "PRETTY_NAME_VAR= -DUSE_PRETTY_NAMES=%USE_PRETTY_NAMES%"
@if defined RCU_OPERATION1_NAME set "OPERATION1_NAME_VAR= -DRCU_OPERATION1_NAME=%RCU_OPERATION1_NAME%"
@if defined RCU_OPERATION2_NAME set "OPERATION2_NAME_VAR= -DRCU_OPERATION2_NAME=%RCU_OPERATION2_NAME%"
@if defined RCU_OPERATION1_CMDLINE set "OPERATION1_CMDLINE_VAR= -DRCU_OPERATION1_CMDLINE=%RCU_OPERATION1_CMDLINE%"
@if defined RCU_OPERATION2_CMDLINE set "OPERATION2_CMDLINE_VAR= -DRCU_OPERATION2_CMDLINE=%RCU_OPERATION2_CMDLINE%"
@if defined RCU_DBMS_OUTPUT_IN_SEPARATE_FILE set "DBMS_OUTPUT_IN_SEPARATE_FILE_VAR= -DRCU_DBMS_OUTPUT_IN_SEPARATE_FILE=%RCU_DBMS_OUTPUT_IN_SEPARATE_FILE%"
@if defined RCU_PRODUCT_NAME set "RCU_PRODUCT_NAME_VAR= -DRCU_PRODUCT_NAME=%RCU_PRODUCT_NAME%"
@if defined USE_TWO_PHASE_RCU set "RCU_TWO_PHASE_VAR= -DUSE_TWO_PHASE_RCU=%USE_TWO_PHASE_RCU%"
@if defined ENABLE_JAVADB set "ENABLE_JAVADB_VAR= -DENABLE_JAVADB=%ENABLE_JAVADB%"

@set "RCU_ENV_VARS=%LOG_LOCATION_VAR%%LOG_LEVEL_VAR%%LOG_NAME_VAR%%LOG_FORMATTER_VAR% %TIMESTAMP_LOG_DIR_VAR%%PRETTY_NAME_VAR%%OPERATION1_NAME_VAR%%OPERATION2_NAME_VAR%%OPERATION1_CMDLINE_VAR%%OPERATION2_CMDLINE_VAR%%DBMS_OUTPUT_IN_SEPARATE_FILE_VAR%%RCU_PRODUCT_NAME_VAR%%RCU_TWO_PHASE_VAR%%ENABLE_JAVADB_VAR%"

@set "OH=%ORACLE_HOME%"
@set "RCU_HOME=%ORACLE_HOME%\oracle_common"
@set "OH_J2EE=%ORACLE_HOME%\j2ee\home"

@set "JLIB_DIR=%RCU_HOME%\jlib"
@set "JRE_DIR=%OH%\jdk\jre"
@set "RCUHELP_FILE=rchlp.jar"

if not defined LANG (
    for /F "skip=1 tokens=3" %%G in ('%SystemRoot%\System32\reg.exe query "HKLM\System\CurrentControlSet\Control\Nls\Language" /v Default') do (
        if "%%G" == "0407" set "RCUHELP_FILE=rchlp_de.jar" & goto MoreVars
        if /I "%%G" == "040c" set "RCUHELP_FILE=rchlp_fr.jar" & goto MoreVars
        if /I "%%G" == "040a" set "RCUHELP_FILE=rchlp_es.jar" & goto MoreVars
        if "%%G" == "0410" set "RCUHELP_FILE=rchlp_it.jar" & goto MoreVars
        if "%%G" == "0411" set "RCUHELP_FILE=rchlp_ja.jar" & goto MoreVars
        if "%%G" == "0412" set "RCUHELP_FILE=rchlp_ko.jar" & goto MoreVars
        if "%%G" == "0416" set "RCUHELP_FILE=rchlp_pt_BR.jar" & goto MoreVars
        if "%%G" == "0804" set "RCUHELP_FILE=rchlp_zh_CN.jar" & goto MoreVars
        if "%%G" == "0404" set "RCUHELP_FILE=rchlp_zh_TW.jar" & goto MoreVars
    )
) else (
    echo %LANG%|%SystemRoot%\System32\find.exe /C /I "de" >nul && ( set "RCUHELP_FILE=rchlp_de.jar" & goto MoreVars )
    echo %LANG%|%SystemRoot%\System32\find.exe /C /I "fr" >nul && ( set "RCUHELP_FILE=rchlp_fr.jar" & goto MoreVars )
    echo %LANG%|%SystemRoot%\System32\find.exe /C /I "es" >nul && ( set "RCUHELP_FILE=rchlp_es.jar" & goto MoreVars )
    echo %LANG%|%SystemRoot%\System32\find.exe /C /I "it" >nul && ( set "RCUHELP_FILE=rchlp_it.jar" & goto MoreVars )
    echo %LANG%|%SystemRoot%\System32\find.exe /C /I "ja" >nul && ( set "RCUHELP_FILE=rchlp_ja.jar" & goto MoreVars )
    echo %LANG%|%SystemRoot%\System32\find.exe /C /I "ko" >nul && ( set "RCUHELP_FILE=rchlp_ko.jar" & goto MoreVars )
    echo %LANG%|%SystemRoot%\System32\find.exe /C /I "pt_BR" >nul && ( set "RCUHELP_FILE=rchlp_pt_BR.jar" & goto MoreVars )
    echo %LANG%|%SystemRoot%\System32\find.exe /C /I "zh_CN" >nul && ( set "RCUHELP_FILE=rchlp_zh_CN.jar" & goto MoreVars )
    echo %LANG%|%SystemRoot%\System32\find.exe /C /I "zh_TW" >nul && ( set "RCUHELP_FILE=rchlp_zh_TW.jar" & goto MoreVars )
)

:MoreVars
@set "RCU_CLASSPATH=%JLIB_DIR%\rcu.jar"
@set "HELPSET_CLASSPATH=%JLIB_DIR%\%RCUHELP_FILE%"
@set "PATH=%RCU_HOME%\bin;%PATH%"
@set "CLASSPATH=%RCU_CLASSPATH%;%HELPSET_CLASSPATH%"

rem If no parameter passed, RCU should start run as silent mode.

if not defined JAVA_HOME (
    set "JAVA_HOME=%JRE_DIR%"
) else (
    if exist "%JAVA_HOME%\jre\bin\javaw.exe" set "JAVA_HOME=%JAVA_HOME%\jre"
)

if not exist "%JAVA_HOME%\bin\java.exe" (
    if exist "%RCU_HOME%\..\oui\bin\getVariable.cmd" (
        @rem INVOKE SCRIPT TO SET THE JAVA_HOME
        call "%RCU_HOME%\..\oui\bin\getVariable.cmd" JAVA_HOME JAVA_HOME
    )
)

if not exist "%JAVA_HOME%\bin\java.exe" (
    if exist "%RCU_HOME%\jdk\" (
        @rem Set the JAVA_HOME to oracle_common\jdk
        set "JAVA_HOME=%RCU_HOME%\jdk"
    )
)

for %%I in ("%JAVA_HOME%") do set "JAVA_HOME=%%~fI"

if not exist "%JAVA_HOME%\bin\java.exe" (
    echo Unable to locate Java at the following location: "%JAVA_HOME%\bin\java".
    echo Please set the correct value for JAVA_HOME or ORACLE_HOME and try again.
    @rem Command endlocal is implicit executed by cmd.exe
    exit /B 1
)

if not "%~1" == "" (
    "%JAVA_HOME%\bin\java.exe" %RCU_JAVA_OPTIONS% -DRCU_HOME="%RCU_HOME%" -DSQLPLUS_HOME="%OH%" -DORACLE_HOME="%OH%" %RCU_ENV_VARS% -DLAUNCH_MODE=%LAUNCH_MODE% -mx128m -classpath "%CLASSPATH%" oracle.sysman.assistants.rcu.Rcu -lockSchemas false %*
) else (
    "%JAVA_HOME%\bin\java.exe" -DRCU_HOME="%RCU_HOME%" -DSQLPLUS_HOME="%OH%" -DORACLE_HOME="%OH%" -DRANDOMIZE_PASSWORDS=true %RCU_ENV_VARS% -DLAUNCH_MODE=%LAUNCH_MODE% -mx128m %RCU_JAVA_OPTIONS% -classpath "%CLASSPATH%" oracle.sysman.assistants.rcu.Rcu
)

endlocal

注意:我希望这个修改后的批处理文件可以工作,因为我无法测试它。

错误消息是由于批处理文件末尾的 %JAVA_HOME%\bin\java 未包含在 " 中引起的。

如果启用命令扩展,则使用 if defined 而不是 if not "variable" == "" 检查环境变量是否存在会更快更安全,如该批处理文件第三行中所确定的那样。 if not defined 优于 if "variable" == "".

如果在执行此命令时未定义一个或多个选项,则最终构建 RCU_ENV_VARS 的环境变量的定义方式可以避免在参数之间的命令行上出现两个或多个 space脚本。选项之间多于一个 space 是没有问题的,但每个选项之间只有一个 space 看起来更好,并且可以很容易地实现,如这里所示。

注册表项 ControlSet001 绝不能用于注册表查询。根本无法保证此注册表项存在。 CurrentControlSet 一直存在。我有一台 PC,其中 ControlSet002 是最后一个已知的良好控制集,ControlSet003 是当前控制集,ControlSet001 根本不存在 Windows 根据HKLM\System\Select.

中的值

不要使用 [] 来比较两个字符串。它们对 Windows 命令处理器没有特殊意义。对两个字符串使用 "IF 条件比较更安全。但请注意 IF 不会从 运行 字符串比较之前的字符串中删除 "。所以如果左边的字符串用"括起来,右边的字符串也必须用".

括起来

字符串比较运算符是 == 而不是 EQUEQU 主要用于比较两个整数值,仅当要比较的两个数字之一无法成功转换为带符号的 32 位整数值时才被解释为字符串比较运算符,例如将两个字符串括在方括号中或双引号。另请参阅我在 上的回答,了解如何通过命令 IF.

进行字符串比较的非常详细的解释

对于 == 应该总是有一个 space 左边和一个 space 右边的 == 100% 正确的语法,就像在 if not "%~1" == "" 上一样 cmd.exe不需要像 if not "%~1"=="" 那样进行自动更正。在 IF 命令行上查看 上可以看到应用的自动更正在使用 IF[=107] 解析和处理命令行后真正执行=] 条件和整个命令块。好吧,对于调试批处理文件,除前两个之外,所有 @ 都会适得其反。

%JAVA_HOME%\bin\java 在批处理文件的最后几行中没有用双引号括起来是错误的原因。用双引号括起来后批处理文件执行成功