• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with a system call in java  RSS feed

 
Michael Paul
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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
 
Jonathan Wolter
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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)

 
Purushoth Thambu
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • 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.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
Muhammad Saifuddin
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
  • 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().
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!