.Bat file code error

Status
Not open for further replies.

Ricks

Right off the assembly line
@echo off
pushd %CD%
cls
set jpath=C:\Program Files\Java\jdk1.6.0_07\bin
cd /d %jpath%
if EXIST "javac.exe" goto FOUND
if NOT EXIST "javac.exe" goto NOTFOUND
:NOTFOUND
cls
echo JAVAC.EXE FILE NOT FOUND
pause
goto END
:FOUND
echo JAVAC.EXE FILE FOUND
echo.
pause
popd
:END

:?:
I have written a .bat code of setting path for JAVA complier but it closes automatically after execution. How to retain the cmd instance for further working.
I'm fed up b'coz i have to do everything manually again even executing the .bat file.
Plz help me out.
Thanx a lot in advance.
 

Bandu

Journeyman
Just add a pause command at the end of the file followed by cmd (or maybe just a cmd at the end might work).

Just in case if your code isn't working, try enclosing your Program Files in double quotes.

Search the Programming forum. Somewhere we do have a thread to set Environment variable PATH, so you might not have to write this code in the first place.
 
Last edited:
OP
R

Ricks

Right off the assembly line
Just add a pause command at the end of the file followed by cmd (or maybe just a cmd at the end might work).

Just in case if your code isn't working, try enclosing your Program Files in double quotes.

Search the Programming forum. Somewhere we do have a thread to set Environment variable PATH, so you might not have to write this code in the first place.

I"ve already added pause command but it doesn't work because it gives a msg "Press any key to continue.." and at pressing any key cmd window closes instantly. Any other solution for this.
 

Bandu

Journeyman
What about cmd at the end of the file?

Update: A more decent solution to your problem:

How are you executing your bat file? Just double clicking on a shortcut that you created? In this case, create a shortcut to your .bat file as cmd /K mybatfile.bat

The /K option will keep the command prompt running.

If you are using the Start -> Run option, instead of typing in your .bat file name directly in the Run box, type cmd /K mybatfile

And what about my other 2 comments? - (a) The c:\Program files will not work. You will have to enclose the string in double quotes; (b) You can use Environment settings to set the Java path. No need to write a .bat code for the same.

- Bandu.
 
Last edited:
Status
Not open for further replies.
Top Bottom