Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes running another application from java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "running another application from java" Watch "running another application from java" New topic
Author

running another application from java

cs sakthi
Greenhorn

Joined: May 11, 2001
Posts: 15
I tried running an exe file from java application using the class Runtime like
class Notepad
{
public static void main(String arg[])
{
try
{
Runtime r = Runtime.getRuntime();
r.exec("C:\\Winnt\\NOTEPAD.EXE");
}
catch(Exception e) {}
}
}
in a Windows NT machine. While running it, it works fine and the application Notepad.exe is opened.
My doubt is that is it possible to open a particular file like
class open
{
public static void main(String arg[])
{
try
{
Runtime r = Runtime.getRuntime();
r.exec("S:\\java-21\\ar.pdf");
}
catch(Exception e) {}
}
}
when i run this nothing is opened and no runtime error is comming. please clear this (with code if possible).
Thanks,
Sakthi.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
You can't actually execute a pdf file. I think that you want to execute Acrobat.exe with the pdf file as an input parameter.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Amit Chawla
Greenhorn

Joined: Mar 26, 2001
Posts: 15
Ya, you cant run a PDF file from JVM, because the JVM does not understand Windows file assciciations....
Modify your code as follows:
try {
Runtime.getRuntime().exec("C:\\Program Files\\Adobe\\Acrobat 4.0\\Reader\\AcroRd32 S:\\java-21\\ar.pdf");
}
catch(Exception e) {
e.printStackTrace();
}
[This message has been edited by Amit Chawla (edited May 17, 2001).]
steve dowdall
Ranch Hand

Joined: May 23, 2001
Posts: 36
Can you run a batch file? If so what would the path look like?
Steve
Umesh Joglekar
Greenhorn

Joined: May 02, 2001
Posts: 16
If you want to simulate the action of windows using the correct apllication to open a given file type when you double click on a file then you really need to find the file association from the registry (assuming you are writing this just for the windows platform) and use the appropriate application in the call to execute()
Umesh Joglekar
Greenhorn

Joined: May 02, 2001
Posts: 16
I mean call to exec()
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: running another application from java
 
Similar Threads
start weblogic server within java code
how to r.exec("java filename");
invoking ms excel from app
launching a non java APP from a java APP
Runtime