• Post Reply Bookmark Topic Watch Topic
  • New Topic

Launch other programs form Java  RSS feed

 
Rich Nello
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I'm working on a small windowed application and creating it using AWT. I have three menus, with a couple of options on each!
If I wanted this application to hold a fourth menu, one which could launch different programs (such as Word, Excel, Netscape, text Pad and others) by referring their exe files, what class or classes should I be reading about 2nite??
I'm just asking because it's an idea I had for an small project which is due in about three weeks! I needs to cover new topics which we didn't cover in class!! I though this was part of my plan, besides GUI!
If it cannot be done (by Greenhorns like myself i.e.), , I'll just have to try and come up with something else
Thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are a set of overloaded exec() methods in the java.lang.Runtime class. Those are what you can use to launch an external program.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One further tip that may not be obvious from reading the doc on Runtime ... you may need to connect to the output streams from the Process that is created and read whatever the program writes to stdout and errout. Some commands won't complete correctly unless you read everything they write. If that sounded too advanced or flat didn't makes sense, get a start on your code and come back again with what you have running.
Another non-obvious tip: If you google for launching web browsers from Java you'll see many examples with RUNDLL32 or something like that. The cool thing about that approach is you name a file on disk and Windows launches the associated program. Just like double-clicking in Windows Explorer. So it can launch IE for an HTML file or URL, or Word or many other programs.
 
Rich Nello
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tips guys !
I'll be back once i've done a bit of coding!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!