Win a copy of Murach's Python Programming this week in the Jython/Python forum!
    Bookmark Topic Watch Topic
  • New Topic

Running Java app with exec() method  RSS feed

 
Alex Teslin
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,

I am trying to compile and run .java file using Runtime.getRuntime().exec()
I am getting 1 as an exit value when i try to compile it.
Also does anyone has a suggestion on if i wanted to run it as well this file assuming i have compiled it. Below is a main method that would not work.

public static void main(String[] args) throws Exception
{
try {
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("javac c://Temp//MainTest.java");
int exitVal = p.waitFor();
System.out.println("Process exitValue: " + exitVal);

System.out.println("Is it compiled");
}
catch(IOException e) {
System.err.println("Error on exec() method");
e.printStackTrace();
}
}

Can anyone suggest what is wrong or what should i be doing instead?

Thank you
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Report post to moderator
I posted a reply to you on this in the Threads and Synchronization Forum.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not post same question to multiple forums.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!