• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to run a java class file using exec

 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since Process.getRunTime().exec() is used for running the system specific commands
If I try to run a java class using
Process p = RunTime.getRuntime().exec("java ABC");
It doesn't work
Can any one suggest me an alternative for it
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Othere than your somewhat random capitalization (the class is "Runtime," the method is "getRuntime()") this should work fine given that "java" in on the path, and the CLASSPATH is set appropriately. How do you know it doesn't work? If you're expecting the output to appear on stdout, note that it won't; it goes to an InputStream that you get read from (get it from Process.getInputStream()). If you want to see the process output, you'd have to read it, then print it out.
 
Author
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You pretty much have to read the ouput stream. Otherwise, the process will block when it's output buffer fills up. When and where this happens is OS dependent, but it is something to worry about.
 
reply
    Bookmark Topic Watch Topic
  • New Topic