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:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* 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
Go Back   Tech Support Forum > The IT Pro > Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Programming A discussion forum for programs and programming used in tech-related businesses.

Reply
 
LinkBack Thread Tools
Old 09-18-2008, 06:18 AM   #1 (permalink)
Registered User
 
Join Date: May 2008
Posts: 16
OS: XP


Idea Batch file execution problem

@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.
Rickiss is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
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

Old 09-18-2008, 02:00 PM   #2 (permalink)
Design Team Member
 
jamiemac2005's Avatar
 
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
__________________

Myspace
jamiemac2005 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-18-2008, 02:03 PM   #3 (permalink)
Design Team Member
 
jamiemac2005's Avatar
 
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%
into
Code:
cmd.exe %jpath%
(or just cmd %jpath%)
to open a new instance of the command prompt at that directory?
__________________

Myspace
jamiemac2005 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-18-2008, 02:21 PM   #4 (permalink)
Design Team Member
 
jamiemac2005's Avatar
 
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"
(/k meaning keep or keep open)

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
__________________

Myspace
jamiemac2005 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-23-2008, 05:13 AM   #5 (permalink)
Registered User
 
Join Date: May 2008
Posts: 16
OS: XP


Re: Batch file execution problem

Quote:
Originally Posted by jamiemac2005 View Post
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"
(/k meaning keep or keep open)

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

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.
Rickiss is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-23-2008, 05:25 AM   #6 (permalink)
Registered User
 
Join Date: May 2008
Posts: 16
OS: XP


Re: Batch file execution problem

Quote:
Originally Posted by jamiemac2005 View Post
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"
(/k meaning keep or keep open)

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

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
Rickiss is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-23-2008, 12:11 PM   #7 (permalink)
Design Team Member
 
jamiemac2005's Avatar
 
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
i got it working for me, and i'm pretty sure it's self explanatory? Let me know how you get on with it.

Cheers,
Jamey
__________________

Myspace
jamiemac2005 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-23-2008, 12:12 PM   #8 (permalink)
Design Team Member
 
jamiemac2005's Avatar
 
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.
__________________

Myspace
jamiemac2005 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-23-2008, 10:59 PM   #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.
Rickiss is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-24-2008, 07:05 AM   #10 (permalink)
Design Team Member
 
jamiemac2005's Avatar
 
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
The above code sets the PATH environment variable for the instance of the command prompt, ensure if you change the code that %PATH% is always appended somewhere so that you don't lose your path variable(which i think would be temporary but you can never be too careful).

Cheers,
Jamey
__________________

Myspace
jamiemac2005 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-25-2008, 04:22 AM   #11 (permalink)
Registered User
 
Join Date: May 2008
Posts: 16
OS: XP


Re: Batch file execution problem

Thanx Jamey,

You have solved my problem. Now everything is going my way. You are a genius man.
Great. THANX

Rickiss is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-25-2008, 06:42 AM   #12 (permalink)
Design Team Member
 
jamiemac2005's Avatar
 
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 =]
__________________

Myspace
jamiemac2005 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 06:20 PM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85