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

Help with a system call in java

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

I am making a system call to open a particular file in ms word. I do it like this:



The problem here is that I do not believe that this exe file doesn't appear in the same path on all computers...I would assume. So how can I generally make a system call that says, look for microsoft word or some flavor? I have it working for the case in which I know where the exe file.

Thanks
Michael
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could have the file location in a properties file. You can read and set properties like this:

(I'm using a junit 4 test to illustrate)

 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can think of two options
(1) Search for all the drives to find the winword.exe and use the path.
(2) Make use of windows file type association without bothering where the exe is located.



The above snippet opens new command window and from there winword or any office suite app is launched and shell is destroyed immediately. You can try cmd.exe /? to find more options.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's also a similar trick using something like "rundll32 url.dll,FileProtocolHandler <<url>>", where"url" is the file you want to open.
 
Sheriff
Posts: 22773
130
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alternatively, java.awt.Desktop should be able to help you with this as well. At least if you have Java 6 or beyond.
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
agree with Rob statement, about referring java.awt.Desktop instead of Runtime.exec().

this may help you to find out the difference between java.awt.Desktop and Runtime.exec().
 
if you think brussel sprouts are yummy, you should try any other food. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic