我必须创建三个批处理文件。两个是配置环境变量,另一个是运行示例。
然后我有confvarsC.bat(C++环境变量)和confvarsJ.bat(Java环境变量)。然后我创建了执行以下操作的 executePortico.bat:测试 java_home 和 rti_home 并调用环境变量文件。但是我需要如果键入“c”的人应该调用 confvarsC.bat 并在 C++ 中运行示例,如果键入“j”的人应该调用 confvarsJ.bat 并运行 Java 示例。
看到我做了:
@echo off
rem ###########################
rem # implementation/version #
rem ###########################
set IMP=portico
rem ################################
rem # check command line arguments #
rem ################################
:checkargs
if "%0" == "" goto usage
if "%1" == "" goto usage
rem #######################
rem # test for JAVA_HOME #
rem #######################
if "%JAVA_HOME%" == "" goto nojava
goto rtihometest
:nojava
echo ERROR Your JAVA_HOME environment variable is not set!
goto usage
rem #######################
rem # test for RTI_HOME #
rem #######################
:rtihometest
if "%0" == "c" goto execC
if "%0" == "j" goto execJ
goto finish
:execC
call C:\Arquivos de programas\Portico\portico-1.0.2\etc\confvarsC.bat
if not "%RTI_HOME%" == "" goto execute
:execJ
call C:\Arquivos de programas\Portico\portico-1.0.2\etc\confvarsJ.bat
if not "%RTI_HOME%" == "" goto execute
############################################
### (target) execute #######################
############################################
:execute
SHIFT
set PATH=%JAVA_HOME%\jre\bin\client;%RTI_HOME%\bin;%PATH%
set RTI_FEDDIR=C:\Arquivos de programas\Portico\portico-1.0.2\examples\cpp\cpp13
set EXEC = "C:\Arquivos de programas\Portico\portico-1.0.2\examples\cpp\cpp13"
if "%0" == "m" goto exec1
:exec1
echo %EXEC%%1%IMP%.exe
pause
%EXEC%%1%IMP%.exe %2
goto finish
:usage
echo usage: executePortico.bat [model] [nome modelo]
goto err
:err
echo Terminated - Error
goto end
:finish
echo Terminated - Normal
:end
我这样做了,请查看我的代码: 但是我有一个问题,当我尝试运行 Java 示例时,他没有进入 executeJava,他总是进入 executeC。
在我的命令提示符中查看:
C:\Portico\portico-1.0.2\exec>executePortico.bat java-hla13 支持 escolha 语言 (J)ava 或 (C)++: j C:\Portico\portico-1.0.2\examples\cpp \cpp13\java-hla13.exe Pressione qualquer tecla para continuar。. . '"C:\Portico\portico-1.0.2\examples\cpp\cpp13\java-hla13.exe"' 不是内部或外部命令、可运行程序或批处理文件。终止 - 正常
Java 示例位于目录中:C:\Portico\portico-1.0.2\examples\java\hla13
@echo off
rem ###########################
rem # implementation/version #
rem ###########################
rem ################################
rem # check command line arguments #
rem ################################
:checkargs
if "%0"=="" goto usage
if "%1"=="" goto usage
set /p language=Por favor escolha a linguagem (J)ava or (C)++:
if %language%=="C" goto execC
if %language%=="J" goto execJ
rem #######################
rem # test for JAVA_HOME #
rem #######################
if "%JAVA_HOME%"=="" goto nojava
goto rtihometest
:nojava
echo ERROR Your JAVA_HOME environment variable is not set!
goto usage
rem #######################
rem # test for RTI_HOME #
rem #######################
:rtihometest
echo EU aqui no executeC
:execC
call C:\Portico\portico-1.0.2\etc\confvarsC.bat
if "%RTI_HOME%"=="" goto nortihome
if not "%RTI_HOME%"=="" goto executeC
:execJ
call C:\Portico\portico-1.0.2\etc\confvarsJ.bat
if "%RTI_HOME%"=="" goto nortihome
if not "%RTI_HOME%"=="" goto executeJava
:nortihome
echo ERROR Your JAVA_HOME environment variable is not set!
goto usage
################################################
### (target) execute C++ #######################
################################################
:executeC
set PATH=%JAVA_HOME%\jre\bin\client;%RTI_HOME%\bin;%PATH%
set RTI_FEDDIR=C:\Portico\portico-1.0.2\examples\cpp\cpp13
set EXEC=C:\Portico\portico-1.0.2\examples\cpp\cpp13\
echo %EXEC%%1.exe
pause
"%EXEC%%1.exe"
goto finish
#################################################
### (target) execute Java #######################
#################################################
:executeJava
set PATH=PATH=%RTI_HOME%\include\ng6;%RTI_HOME%\lib;%RTI_HOME%\bin;%JAVA_HOME%\bin;%PATH%
set ClassPath=%RTI_HOME%\lib\portico.jar
set RTI_FEDDIR=C:\Portico\portico-1.0.2\examples\java\hla13
set EXECUTA=C:\Portico\portico-1.0.2\examples\java\hla13\
echo %EXECUTA%java-hla13.jar
pause
"%EXECUTA%java-hla13.jar"
goto finish
:usage
echo usage: executePortico.bat [model] [nome modelo]
goto err
:err
echo Terminated - Error
goto end
:finish
echo Terminated - Normal
:end