![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Programming A discussion forum for programs and programming used in tech-related businesses. |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: May 2008
Posts: 16
OS: XP
|
@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. |
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#2 (permalink) |
|
Design Team Member
Join Date: Jul 2007
Location: Coventry, UK
Posts: 1,879
OS: Vista, various linux distros
|
Re: Batch file execution problem
To see the result of the batch file you should run it from a command prompt rather than just double clicking from explorer... why don't you just add java's "bin" directory to the path environment variable?
I assume you're doing this so after the script has run you can compile a .java file?(If i'm completely wrong please do post with the actual reason you're doing it) You could also add an "autocompile" like entry to the .java file context menu(If you want more info on this i can go into it in more detail)... Cheers =] Jamey |
|
|
|
|
|
#3 (permalink) |
|
Design Team Member
Join Date: Jul 2007
Location: Coventry, UK
Posts: 1,879
OS: Vista, various linux distros
|
Re: Batch file execution problem
oh p.s. i'm not sure if the directory you "cd" into will remain in the command prompt if you run it from the command prompt...
you could change Code:
cd /d %jpath% Code:
cmd.exe %jpath% to open a new instance of the command prompt at that directory? |
|
|
|
|
|
#4 (permalink) |
|
Design Team Member
Join Date: Jul 2007
Location: Coventry, UK
Posts: 1,879
OS: Vista, various linux distros
|
Re: Batch file execution problem
Hey again, i've done some reading =] cmd.exe /? brings up the command line parameters for cmd.exe and if you run:
Code:
cmd /k "[path to your batch file]" e.g. cmd /k "D:\Command-line Params\cmd\test with k param.bat" the command prompt stays open after the .bat file has run (yet again this could be added to the .bat context menu)... oh and the path does remain as it's changed in the bat file... Cheers, Jamey |
|
|
|
|
|
#5 (permalink) | |
|
Registered User
Join Date: May 2008
Posts: 16
OS: XP
|
Re: Batch file execution problem
Quote:
Jamey, You mean to say that I have to create a new bat file for this purpose. Is it not possible to do everything in the same .bat file. |
|
|
|
|
|
|
#6 (permalink) | |
|
Registered User
Join Date: May 2008
Posts: 16
OS: XP
|
Re: Batch file execution problem
Quote:
Jamey, acc. to your saying, I've edited my code but i still have a problem with this. Now, this time I've to call the .bat file itself after executing the same file. Then i have to exit from it for further processing. I know there's very little error. Can you help me in this matter. Here is the code... @echo off pushd %CD% cmd /k 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 |
|
|
|
|
|
|
#7 (permalink) |
|
Design Team Member
Join Date: Jul 2007
Location: Coventry, UK
Posts: 1,879
OS: Vista, various linux distros
|
Re: Batch file execution problem
Hey, i had a few problems trying to work this out...
Basically i understand why your code isn't working(because the batch file waits for an exit code before beginning to run again)... but not how to fix it... If you had another batch file launching this file it would work (but i understand you want it in one batch file)... So i came up with this: Code:
@echo off if [%1] == [keptOpen] goto RUNSCRIPT cmd /k "test.bat keptOpen" goto END :RUNSCRIPT 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 Cheers, Jamey |
|
|
|
|
|
#8 (permalink) |
|
Design Team Member
Join Date: Jul 2007
Location: Coventry, UK
Posts: 1,879
OS: Vista, various linux distros
|
Re: Batch file execution problem
oh p.s. the string test.bat is what that batch file was named on my local pc so it would need changing on yours to whatever it is that you've called it.
|
|
|
|
|
|
#9 (permalink) |
|
Registered User
Join Date: May 2008
Posts: 16
OS: XP
|
Re: Batch file execution problem
Jamey,
Thanx for your support but the code is still not working for me. Now the cmd window will kept open and I got the msg that JAVAC.exe found but when i execute the javac then again... Javac.exe is not recognized as internal or external command. It seems that .bat code is unable in setting path. Thx again Jamey for your support. Last edited by Rickiss; 09-23-2008 at 11:25 PM. |
|
|
|
|
|
#10 (permalink) |
|
Design Team Member
Join Date: Jul 2007
Location: Coventry, UK
Posts: 1,879
OS: Vista, various linux distros
|
Re: Batch file execution problem
Hey, it's because you popd the beginning directory, once the script is run use %jpath%\javac.exe to run javac or try this code:
Code:
@echo off if [%1] == [keptOpen] goto RUNSCRIPT cmd /k "test.bat keptOpen" goto END :RUNSCRIPT 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. rem the following line sets the path environment variable to include the jpath variable set PATH=%jpath%;%PATH% pause popd :END Cheers, Jamey |
|
|
|
|
|
#12 (permalink) |
|
Design Team Member
Join Date: Jul 2007
Location: Coventry, UK
Posts: 1,879
OS: Vista, various linux distros
|
Re: Batch file execution problem
Thats k =] Thx to you too, i haven't played around with batch files in a big way but this gave me some more experience of them...
Cheers, Jamey =] |
|
|
|
![]() |
| Thread Tools | |
|
|