I suspect that you have a space in the path to your file. Instead
use the alternative exec method as follows which will work if
spaces are in your (absolute path) filename:
Runtime.getRuntime().exec(new String[] { "open", fileName });
Best Regards,
Ian Cheyne
On 21 Jan 2006, at 01:24, Dan Crow wrote:
Hi guys,
I'm trying to launch either Adobe Acrobat or Preview.app from my
Java application so I can display a PDF file to the user. I'm
doing this on Mac by using Runtime.exec to invoke the open command.
I've tried various different open commands through the following
code:
private static void launch(String fileName, String
applicationName)
{
String cmd = "open " + fileName;
try
{
System.out.println("Executing command: " + cmd);
Runtime.getRuntime().exec(cmd);
}
catch (IOException e)
{
JOptionPane.showMessageDialog(null, "Could not open " +
applicationName);
e.printStackTrace();
}
}
Whatever I set cmd to, nothing happens. The application doesn't
launch, I don't get an error message or exception, it just
silently fails.
Two odd things:
1) The same code opens my default web browser just fine if I pass
a URL to this method in the fileName parameter
2) If I invoke the exact command that's println'ed out from
Terminal, then the PDF file is opened as expected, so the filename
(which is an absolute path) is valid.
Can anyone offer any clues about this? What have I missed?
Many thanks as always,
Dan
--
Dan Crow
VP of Product and Technology
email@hidden
Blurb, Inc.
88 Kearny Street, Suite 1610
San Francisco, CA 94108
415.362.2067 x663 (office)
415.290.6184 (mobile)
415.362.2078 (fax)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden
This email sent to email@hidden