0

I need that if the person typing "c" should run the examples in C + +, if the person type "j" should run the Java examples.

But:

1- Does not recognize when I type “c” or “j”, if I type "j", he makes executeC, if I choose "c" also makes executeC not entering this executeJava. Then changed to a numerical value, where if I type 3 - executeC, if I type 4 - executeJava. So if I type 3 it accesses the directory C:\Portico\portico-1.0.2\examples\cpp\cpp13 and processes executeC, 2- If I type 4 it accesses the directory C:\Portico\portico-1.0.2\examples\java\hla13, but does not run, simply ends.

See what i do in the command prompt

C:\Portico\portico-1.0.2\exec>executePortico.bat main
Choose (J)ava or (C)++: 3
C:\Portico\portico-1.0.2\examples\cpp\cpp13\main.exe
Pressione qualquer tecla para continuar. . .
Created Federation
Joined Federation as exampleFederate
Successfully registered sync point: ReadyToRun

C:\Portico\portico-1.0.2\exec>executePortico.bat java-hla13
Choose (J)ava or (C)++: 4
C:\Portico\portico-1.0.2\examples\java\hla13\java-hla13.jar
Pressione qualquer tecla para continuar. . .
Terminated - Normal
C:\Portico\portico-1.0.2\exec> 

See my code please:

@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%==3 goto execC
if %language%==4 goto execJ



rem #######################
rem # test for JAVA_HOME  #
rem #######################
set JAVA=java
set JAVAC=javac
set JAR=jar
if "%JAVA_HOME%"=="" goto nojava

set JAVA="%JAVA_HOME%\bin\java"
set JAVAC="%JAVA_HOME%\bin\javac"
set JAR="%JAVA_HOME%\bin\jar"
goto rtihometest

:nojava
echo ERROR Your JAVA_HOME environment variable is not set!

goto usage


rem #######################
rem # test for RTI_HOME   #
rem #######################
:rtihometest


:execC
call C:\Portico\portico-1.0.2\etc\confvarsC.bat
if "%RTI_HOME%"=="" goto nortihome 
if not "%RTI_HOME%"=="" goto executeC

goto End


:execJ
call C:\Portico\portico-1.0.2\etc\confvarsJ.bat
if "%RTI_HOME%"=="" goto nortihome 
if not "%RTI_HOME%"=="" goto executeJava

goto End


:nortihome
echo ERROR Your JAVA_HOME environment variable is not set!
goto usage


############################################
### (target) execute #######################
############################################
: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


: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
David
  • 171
  • 2
  • 6
  • 18
  • The c/j/3/4 switch is working, as it does different things, so those labels are OK. But the command `C:\Portico\portico-1.0.2\examples\java\hla13\java-hla13.jar` isn't doing anything. Does it work directly from the command prompt? Is the folder correct? – AjV Jsy Feb 20 '13 at 14:28
  • Your question is very unclear. Are you asking about the IF statements (as in the title), if so is this just a duplicate of your earlier question: http://stackoverflow.com/questions/14733516/batch-files-checking-arguments Or, are you asking about how to execute the jar file, in which case see here: http://stackoverflow.com/questions/1238145/how-to-run-a-jar-file – Vicky Feb 21 '13 at 09:55
  • Please figure out what your exact question is, come up with a simple example that shows the problem, and post that. Don't dump your entire program on us and say "it doesn't work, figure it out for me." – librik Oct 02 '13 at 01:52

1 Answers1

0

It seems you want to enter J or C to branch, but you were testing for 3 and 4. They would both fail and the code would merrily continue along because there was no other logic to handle incorrect input. Try this segment:

if "%~0"=="" goto usage
if "%~1"=="" goto usage

set /p "language=Por favor escolha a linguagem (J)ava or (C)++: "

if /i "%language%"=="C" goto execC
if /i "%language%"=="J" goto execJ
echo incorrect input - quitting
goto :EOF
foxidrive
  • 40,353
  • 10
  • 53
  • 68