Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Runtime.getRuntime().exec()

 
Garandi Garandi
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
If I want to invoke an executable from a java program I use the following.
Runtime.getRuntime().exec("notepad");
This works.
HOW TO INVOKE "EXCEL" ?
Thank you in advance
Garandi
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi v,
notepad is a name of the executable for the Notepad and similarly you should be able to use the executable for the excel that is 'excel.exe'.
u might have to give the full path to the exe of the excel on ur machine...
try it..i don't have ms excel right now on my machine so i can't comment more..
regards
maulin
 
Malhar Barai
Author
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you would have to give the path of excel.exe for it to get working...as notepad.exe is in \windows folder...but same is not with excel.exe
so put Runtime.getRuntime().exec("<path>/excel.exe");
this shud work
MB
 
Garandi Garandi
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q1:-But how to find the path for excel.exe on a given arbitrary machine?
Q2:- How to open an excel file, eg TestFile.xls
Thank you
Jawad
[ April 01, 2003: Message edited by: Garandi Garandi ]
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Garandi,
here is the code i tried on Win2k.
on systems that has "command" instead of "cmd" you might face problem.


it runs for me...
hope this helps.
regards
maulin
 
Garandi Garandi
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Maulin,
It works, thank you very much.
Garandi
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Win2k puts "start" is not necessary, it�s already to find alone the path. I am brazilian, sorry for my english, I am still learning the english language.
 
Garandi Garandi
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my code I write to an excel file and then try to close the output stream, after that invoke

But the problem is that some times it does not invoke the excel file.
Q1:- How to make sure it invokes the excel file always.
Thank you in advance
Garandi
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also exec RunDLL32 to launch a file. This seems to be exactly like double-clicking a file in Windows Explorer. The benefit is that you don't have to know the path to the Excel executable.
Here's an example you'll find thousands of places on the web for launching a URL into IE. The file can be an Internet URL like this one, or a local file. What they don't all say is that you can launch any file with an association this way.

Copy the part in quotes and type it into a dos box for fun.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic