We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,985 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

creating batch file for java application

this is in execute method()

{ 
 Process p = Runtime.getRuntime().exec(command, env);
}

System.out.println(r.execute(" C:\\Program Files\\Java\\jdk1.6.0_21\\bin\\javac demo.java” , null));
System.out.println(r.execute(" C:\\Program Files\\Java\\jdk1.6.0_21\\bin\\java demo”, null));

i want to run demo.java from this code i used timer class also.
i got the error "Illegal execution time" i dont know why
when i run this program in eclipse it does not give me output
but when i run this on command prompt then it gives me error
can anyone help me
Thanks in advanced!!!!!!!!

3
Contributors
2
Replies
5 Days
Discussion Span
1 Year Ago
Last Updated
3
Views
Pravinrasal
Junior Poster in Training
54 posts since Jul 2011
Reputation Points: 19
Solved Threads: 0
Skill Endorsements: 0

You seem to be having problems running DOS commands from within Java.

The problem is, you can't do that as if you were typing in command prompt.

This thread explains it short but with the essentials:
http://www.devx.com/tips/Tip/42644

To create a batch file, simply open notepad, type the code you'd type in command prompt, save as, and end your file name with ".bat".

In case you have lots of code, it might be easier to make a batchfile, either through the method described above, or through Java IO to write the file, and execute that from within your java program.

Aviras

Aviras
Junior Poster in Training
87 posts since Jul 2008
Reputation Points: 24
Solved Threads: 8
Skill Endorsements: 0

i want to run demo.java from this code

Normally files with the .java extension contain text that is a source for a java program. You "run" the .class file that is created by the javac compiler.

If you want to "run"/execute the .class file you could call its main method directly:
demo.main(new String[]{});

NormR1
Posting Sage
Team Colleague
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0779 seconds using 2.66MB