• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

running a java program

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to run a package containing .class files from a java program for this i have written:
Process tempProcess=Runtime.getRuntime().exec("java "+ mainClassName,null,new java.io.File(absolutePackagePath));
tempProcess.waitFor();
but the problem is that i am not able to given input to this tempProcess or see output of it.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That code may produce some output or need some input that your code isn't handling. See this article for pitfalls to avoid when using Runtime.exec.
 
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aside from the issues that Ulf pointed out, are you also sure you want to start a new JVM to run your sub-application? Depending on exactly what you want to achieve, you may find the Reflection API more useful and appropriate. Things get slightly complicated if the .class files aren't already in your current classpath (you may need to create a new class loader), but this may still be better than using Runtime.exec().
 
Those are the largest trousers in the world! Especially when next to this ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic