0

成功安装 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

我的 cmd 窗口的屏幕截图

这是我的 PATH 环境变量值:

C:\app\gadmin\product\18.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%

4

2 回答 2

0

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

于 2020-03-29T05:58:48.373 回答
0

我建议修改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

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

表达式%~dp0扩展为始终以反斜杠结尾的批处理文件的完全限定路径。因此%~dp0,永远不应该直接或间接地通过环境变量INTERNAL_SCRIPTPATH与带有文件/文件夹名称的附加反斜杠在这里完成连接。否则会导致扩展路径,Windows在将文件/文件夹名称与文件系统的路径一起传递之前\\需要将其更正为单个路径。这就是在命令CALL的参数字符串\末尾附加反斜杠并删除反斜杠的原因。%WLS_ORACLE_HOME%\oracle_common\bin

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

我建议阅读有关如何使用空格设置环境变量的答案?以及为什么在命令行上使用 'set var = text' 后没有带有 'echo %var%' 的字符串输出?了解为什么最好将variable=value命令SET的参数字符串用双引号括起来,"并在变量名的左端而不是变量值的开头。这有很大的不同。

扩展命令行中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如果在执行此脚本时未定义一个或多个选项,则最终构建的环境变量的定义方式是避免参数之间的命令行上有两个或多个空格。选项之间有多个空格是没有问题的,但是每个选项之间只有一个空格看起来会更好,并且可以很容易地实现,因为它可以在这里看到。

ControlSet001永远不要在注册表查询中使用注册表项。无法保证此注册表项完全存在。总有CurrentControlSet存在的。我有一台 PC,它ControlSet002是最后一个已知的良好控制集,ControlSet003是当前的控制集,并且ControlSet001根本不存在 Windows 根据HKLM\System\Select.

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

字符串比较运算符 is==和 not EQUEQU主要用于比较两个整数值,并且仅当要比较的两个数字之一无法成功转换为带符号的 32 位整数值时才被解释为字符串比较运算符,例如将两个字符串括在方括号或双引号中。另请参阅我对Windows 批处理文件中与 NEQ、LSS、GTR 等等效的符号的回答,以非常详细地说明如何通过命令IF完成字符串比较。

应该总是有一个空格和一个空格来==保证 100% 正确的语法 onif not "%~1" == ""不需要cmd.exe像 on 那样进行自动更正if not "%~1"==""在使用IF条件和整个命令块解析和处理命令行之后,在查看真正执行的IF命令行时,可以在调试批处理文件时看到应用的自动校正。好吧,对于调试批处理文件,除了前两个之外,一切都适得其反。@

于 2020-03-28T11:39:40.070 回答