Opening a file via Runtime.exec() on Mac OS X

I'm having a hard time opening a file programatically on Mac OS X.
The following code works only if the filepath/filename doesn't contain a space:
String filepath;
Runtime rt = Runtime.getRuntime();
rt.exec( "open " + filepath);From a terminal, typing open + surrounding the filepath with either apostrophes or quotes and OS X will open the file no problem, even if it has spaces.
So I tried modifying my call:
filepath = "\"" + filepath + "\"";
rt.exec( "open " + filepath);...then nothing happens. No error, no popup, no exception thrown...nothing. Same thing if I use apostrophes vice quotes.
Any ideas? I'm using JDK 5.0 as 6.0 is not yet supported by Apple.
Thanks in advance.

assuming open is an app, not a command within a shell... what about this:
String[] cmd = { "open", filepath }; // with out quotes
rt.exec(cmd);

Similar Messages

  • Problem opening a file from Runtime.exec()

    hi
    I'm trying to open a certificate (.cer), from my java code.
    If I go on a windows command, and I type only the name of my certificate ( f:\certificate.cer), it is opened.
    If I use the java code
    Process process = Runtime.getRuntime().exec("F:\\certificate.cer");it doesn't work:
    java.io.IOException: CreateProcess: "f:\oid.crt" error=193
    anybody knows what I can do to make it work?
    Thanks in advance
    Philippe

    For windows you need to used the cmd.exe to do what you want.
    i.e. cmd /c f:\certificate.cer
    Process process = Runtime.getRuntime().exec("cmd.exe /c F:\\certificate.cer");At a command prompt, for more help on cmd.exe type: cmd /?
    Also for help on a related command, type: start /?
    Also read http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • How to capture output of java files using Runtime.exec

    Hi guys,
    I'm trying to capture output of java files using Runtime.exec but I don't know how. I keep receiving error message "java.lang.NoClassDefFoundError:" but I don't know how to :(
    import java.io.*;
    public class CmdExec {
      public CmdExec() {
      public static void main(String argv[]){
         try {
         String line;
         Runtime rt = Runtime.getRuntime();
         String[] cmd = new String[2];
         cmd[0] = "javac";
         cmd[1] = "I:\\My Documents\\My file\\CSM\\CSM00\\SmartQ\\src\\E.java";
         Process proc = rt.exec(cmd);
         cmd = new String[2];
         cmd[0] = "javac";
         cmd[1] = "I:\\My Documents\\My file\\CSM\\CSM00\\SmartQ\\src\\E";
         proc = rt.exec(cmd);
         //BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
         BufferedReader input = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
         while ((line = input.readLine()) != null) {
            System.out.println(line);
         input.close();
        catch (Exception err) {
         err.printStackTrace();
    public class E {
        public static void main(String[] args) {
            System.out.println("hello world!!!!");
    }Please help :)

    Javapedia: Classpath
    How Classes are Found
    Setting the class path (Windows)
    Setting the class path (Solaris/Linux)
    Understanding the Java ClassLoader
    java -cp .;<any other directories or jars> YourClassNameYou get a NoClassDefFoundError message because the JVM (Java Virtual Machine) can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.
    javac -classpath .;<any additional jar files or directories> YourClassName.javaYou get a "cannot resolve symbol" message because the compiler can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.

  • Open Batch file during Runtime

    How Can i execute a batch file from java program.?
    my batch file only have this command """" java Server""""
    Server is the name of my java file application.

    Runtime.exec() is the thing you want.
    BUT before you use it, read this:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps_p.html
    and this:
    http://mindprod.com/jgloss/exec.html
    and, of course, this:
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
    -T-

  • Unable to open raw files in elements 11 on Mac 10.9.1

    Unable to open raw files in Elements 11 on Mac 10.9.1

    Here is PSE forum http://forums.adobe.com/community/photoshop_elements

  • Problems opening .pdf files created in Windows in MAC

    My clients that are using Macs are having problems opening password protected PDFs that I created in Windows. Any suggestions?

    Are your clients using Adobe Reader on Mac, or the built-in Mac OS Preview?  Preview does NOT support the full PDF standard :(.
    From: Adobe Forums <[email protected]<mailto:[email protected]>>
    Reply-To: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>>
    Date: Mon, 26 Sep 2011 15:04:18 -0700
    To: Leonard Rosenthol <[email protected]<mailto:[email protected]>>
    Subject: Problems opening .pdf files created in Windows in MAC
    Problems opening .pdf files created in Windows in MAC
    created by Hollcy<http://forums.adobe.com/people/Hollcy> in PDF Language and Specifications - View the full discussion<http://forums.adobe.com/message/3939175#3939175

  • Hi, I cannot open nef files in elements 4 for mac

    Hi,
    I cannot open nef files in elements 4 for mac.

    For the D3000 you need version 7 or higher. PSE4 is too old.
    You would need to download the converter to change NEF to DNG to open them in PSE4
    http://www.adobe.com/support/downloads/detail.jsp?ftpID=4575

  • Runtime.exec on Mac

    How to use runtime.exec on Mac. I need to start iCal and I don't know how. calling runtime.exec("iCal") , runtime.exec("/Applications/iCal") and runtime.exec("/Applications/iCal.app") throws error. Please help. I don't know anything about Mac.

    Yes I did the second way and it gives a runtime
    error. I wrote a program that accepts argument and
    then executes it using getRuntime().exec(argument);
    I am still not able to start any programs under Mac.
    The problem is that I don't know anything about Mac.Suggestion.
    Figure out how to launch it from the terminal. That should give you an idea of what the command should be I think.
    Sorry I can't remember OTOH how to get into the terminal but I know you can.

  • Unable to open encrypted files moved from PC to Mac

    I am running Acrobat Pro XI on a PC (Windows version 8.1) and Have Acrobat Pro XI (Mac version) on a new MacBook Pro Retina 13".  I am able to "transfer" files from the PC to the Mac via Dropbox.  However, only the unencrypted files will open on the Mac.
    As soon as I use a password to encrypt the file on the PC (i.e. Password merely for opening the .pdf file) and then trf via Dropbox to the Mac, it (the Mac) returns the message ...  "The password is incorrect.  Please make sure that the Caps Lock is not on by mistake and try again."...  I have tried repeatedly , checking Caps Lock/Password etc.  The password is correct and works fine on the PC.  I have even tried re-installing Acrobat on the Mac but this has made no difference.
    Assistance will be greatly appreciated.
    Dave R

    Ok, that still leaves two questions
    - What version of Acrobat or Reader is in use on each system?
    - Did you use any special character in the password?
    To that I would add
    - Do you use a hyphen in the password?

  • Problem wiht Running Batch File using Runtime.exec()

    I am writting one program which will create a jar file using a windows Batch file.
    The main program is in the folder "d:\CmdExec.java".
    The other one to which a jar file to be created is in the folder "e:\folder\HelloWorld.class"
    The contents inside the "e:\folder" are
    e:\folder\HelloWorld.class
    e:\folder\mainClass.txt
    e:\folder\run.bat
    The mainClass.txt contains "Main-Class: HelloWorld"
    The Run.bat file contains "jar cmf mainClass.txt HelloWorld.jar *.class"
    The coding for CmdExec.java is as follows
    import java.io.*;
    import java.awt.Desktop;
    public class CmdExec {
    public static void main(String argv[]) {
    try {
    Desktop desktop = null;
    if (Desktop.isDesktopSupported()) {
    desktop = Desktop.getDesktop();
    desktop.open(new File("e:\\folder\\run.bat"));
    catch (Exception err) {
    err.printStackTrace();
    When i double click the file e:\folder\Run.bat, it will create a jar file for HelloWorld.class.
    But, i want to create that jar file using the java program CmdExec.java.
    When i run CmdExec.java, the batch file is opened. But it shows error as "Can't find the specified file"
    But when i copy the following files to "d:\",
    e:\folder\HelloWorld.class
    e:\folder\mainClass.txt
    the jar file is created using the CmdExec.java.
    But,
    e:\folder\HelloWorld.class
    e:\folder\mainClass.txt
    these files should be in the folder"e:\folder" only.
    Can anyone Help me this Problem?
    Or Anyother way for creating a jar file for one program by using another program?
    Help me soon.............

    Try this. It's not running a bat file. You can say it almost is a bat file.
    import java.io.*;
    import java.util.Scanner;
    public class CmdExec {
        public static void main(String argv[]) {
            try {
                Process p = Runtime.getRuntime().exec("jar cmf mainClass.txt HelloWorld.jar *.class");
                Scanner s1=new Scanner(new InputStreamReader(p.getInputStream()));
                while(s1.hasNextLine())
                    System.out.println(s1.nextLine());
                p.waitFor();
                System.out.println(p.exitValue());
                if(p.exitValue()==0)
                    System.out.println("Okay");
                else
                    System.out.println("Error");
            catch (Exception ex) {
                ex.printStackTrace();
    }Run it in the same folder as mainClass.txt
    Edited by: ColacX on Aug 1, 2008 10:35 AM

  • "Open method of Workbooks class failed" when opening Excel file via Internet Explorer

    (apologies, I posted this first to the general Office 2010 forum, but then realized this was probably a better spot to post)
    We have an Excel COM add-in installed on users' PCs.  This add-in responds to workbook open events by opening a particular XLA file (also deployed to the PC) to make certain features available.  This process works flawlessly when Excel files are
    opened locally - but when a user attempts to open an Excel file from an IE link, we get the following error: "Open method of Workbooks class failed".  This is happening on the line that is trying to open the XLA file.  This only happens
    when launching an Excel link from IE - works fine in Chrome or Firefox.
    I have found several posts on this topic, but no solutions:
    1. This post (https://social.msdn.microsoft.com/forums/office/en-US/73c96005-84af-4648-b103-32b677205be3/open-method-of-workbooks-class-failed)
    is the closest to our problem.  In this case, the "answer" was that the user may not have access to the 2nd workbook being opened.  But in our case, we're opening an XLA that is on the local machine, and I've confirmed that it is not
    corrupt and accessible (read & write, just in case!) to Everyone.
    2. This (very old) post (http://www.pcreview.co.uk/forums/open-method-workbooks-fails-excel-hosted-ie-t965608.html)
    seems similar, but is talking about opening Excel inside of IE.  This is not what we're doing - the link is supposed to (and does) open Excel outside of IE.  Interestingly, Excel.exe is being launched with the "-embedded" flag, even
    though it isn't running in the IE window.  When launching Excel by opening the file locally, Excel.exe is run with the "/dde" flag instead.  Clearly the "-embedded" mode is what is causing the problem.  I could change the
    links on the web page to use some JavaScript to open Excel differently... unfortunately, the links are actually generated by SharePoint (the Excel files are in a SP repository), so this is not really an option.
    3. This Microsoft KB article (http://support.microsoft.com/kb/268016) talks about problems opening an XLA directly from IE... but this is the case of a link pointing
    directly to an XLA file, not opening a regular workbook that in turn opens an XLA, as is my case.  In fact, this article specifically points out in the "More Information" section that "End users do not normally open XLAs; instead they open
    an XLS that (if needed) loads one or more XLAs during startup." ==> precisely what I'm trying to do that is giving me the error!
    I've replicated the situation with a very simple COM add-in (created in VS2010 using VB.Net) and a very simple XLA file (does nothing, just pops up a message in auto_open).  For anyone wanting to try it out, here is the exact test case:
    1. In Excel, create a simple XLA file containing only the following code, and save it in C:\TEMP\dummy.xla:
    Sub Auto_Open()
    MsgBox "Auto Open fired"
    End Sub
    2. In Visual Studio, create a new Excel 2010 Add-In.  I created mine via Visual Basic, but I doubt the choice of language matters.  Place the following code in ThisAddin.vb:
    Public Class ThisAddIn
    Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
    AddHandler Me.Application.WorkbookOpen, AddressOf Application_WorkbookOpen
    End Sub
    Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
    End Sub
    Sub Application_WorkbookOpen(ByVal workbook As Excel.Workbook)
    On Error GoTo ErrHandler
    If (Not workbook.Name.Contains("dummy.xla")) Then
    MsgBox("Workbook open")
    Application.Workbooks.Open("C:\temp\dummy.xla")
    Application.Workbooks("dummy.xla").RunAutoMacros(Excel.XlRunAutoMacro.xlAutoOpen)
    End If
    Exit Sub
    ErrHandler:
    MsgBox(Err.Description)
    End Sub
    End Class
    3. Build & publish this add-in and install it on the same machine as the XLA created in step 1.
    4. Create and save an empty Excel workbook (I called mine WayneTest1.xlsx) - save it locally (on your desktop), and put a copy somewhere on your web server (I put mine directly in c:\inetpub).
    5. Create an HTML file with a link to that workbook, saving it to the same web server location - here is mine:
    <html>
    <body>
    <a href="WayneTest1.xlsx">Link to Excel file</a>
    </body>
    </html>
    6. Double click the workbook on your desktop (from step 4) - opens fine, I get the "workbook open" message, following by the "Auto Open fired" message.
    7. In Internet Explorer, navigate to the HTML file specified in step 5 and click on the link - when prompted, select "Open" - I get the "workbook open" message, following by the error message "Open method of Workbooks class failed".
    Here are a few things I've ruled out / tried so far:
    - Unchecked all the "Protected View" settings in Excel, made no difference
    - Unchecked all the "File block settings" in Excel, made no difference
    - Made sure dummy.xla was open for read & write to Everyone
    - Made sure the web page was in Trusted sites and set the security level to Low for those sites in IE
    - Tried making the local desktop file (step 6) readonly, made no difference (i.e. launching it locally still worked fine)
    - Tried using Excel 2013 - made no difference
    Any ideas / suggestions?

    Hello Wayne,
    Apologies for the delay.
    I went through your post and tried to reproduce the issue. I was able to reproduce it. Based
    on its complexity and as it requires more in-depth analysis, your question falls into the paid support category which requires a more in-depth level of support.
    Please visit the below link to see the various paid support options that are
    available to better meet your needs. http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone
    Thanks,
    Anush

  • Cannot open PDF files in AIR app on Mac OS error 3204

    Hello,
    I am having trouble opening a PDF file in adobe air application on Mac OS 10.9.2. I already installed adobe reader 11 and air on mac.
    I also traced HTMLLoader.pdfCapatibility, which returns 3204 (An error was returned by the OS when trying to load the Adobe Reader or Acrobat application or one of its necessary libraries.) .
    I am showing you some sample code to you.
    if(HTMLLoader.pdfCapability == HTMLPDFCapability.STATUS_OK)
                var request:URLRequest = new URLRequest(tempFile.url);
                pdf.load(request);
                var ui:UIComponent = new UIComponent();
                ui.addChild(pdf)
                container.addChild(ui);
      else
      trace("PDF cannot be displayed. Error code:",HTMLLoader.pdfCapability);
    It shows the output :  PDF cannot be displayed. Error code: 3204
    Please let me know if anyone have any ideas ............asap

    Hi jon123_123,
    I dont understand what you mean by opening PDF file in Adobe Air, that is platform.
    You should try uninstall Adobe Reader and install Latest version of Adobe Reader with latest updates patches and check again.
    Regards,
    Ajlan Huda.

  • I cannot open pdf files with Firefox using a Mac 10.5.8 OSX

    The new version of Firefox does not support opening pdf files using a Mac 1.5.8 OSX with an Intel processor. Anything I can do?

    ios 6 requires itunes 10.6.3 or higher which requires Mac OS 10.6.8 or higher

  • Can't open .ppt files in MS Powerpoint for Mac

    I recently upgarded to OSX Maveriks 10.9.1 and now have Mail 7.1.
    I am receiving .ppt files as email attachments and I want them to open in Micorsoft Powerpoint by default (I have Office for Mac installed). Currently it opens in Keynote and I don't want that to happen. Before I installed Mavericks i was able to do this and opened .ppt files in Keynote only if I wanted to.
    Hope I have articulated the problem well and loo fwd to solutions.
    Thanks
    Rach

    Hey Rach0k,
    Thanks for the question. You can configure which application will open .ppt documents by following these steps:
    OS X Mavericks: Choose an app to open a document
    http://support.apple.com/kb/PH14279
    Permanently change the document’s app
    1. Select the document, then choose File > Get Info.
    2. In the Info window, click the triangle next to “Open with” to expand the section.
    3. Choose an app from the pop-up menu, or choose Other to locate a different app on your Mac. To download and install a new app, choose App Store.
    4. If you want to use that app to open all documents of the same type as the current document and created by the same app, click Change All.
    Thanks,
    Matt M.

  • Facing problems to open PDF files in iBooks in my Mac, how can I fix it?

    I didn't use to have problems opening and reading my PDF files in iBooks.
    However, yesterday my MacBookPro started not to open any PDF files.
    Its books, the app would open normally, but PDF files it just blinks the apps at the bottom of its screen but do not open any file.

    Hello,
    I guess my question here is why would PDF's open in Preview and not in iBooks? What is the point of adding them to iBooks if it just route them elsewhere?
    Thanks,
    Robert

Maybe you are looking for

  • Camera Raw installing images

    I have just started shooting in Camera raw, problem I have is that when I save the files, it says there are no images to save,only way that i can save my images is to open Photoshop, go to file, open search for the card reader and open it to show the

  • AnyConnect 3.1.01065 error - Failed to install AnyConnect VPN Profile because of file move error. A VPN connection cannot be established.

    I've got a user running: AnyConnect 3.1.01065 on Windows 7 64bit. Several weeks ago she started encountering the following error: -after logging into Windows and launching the AnyConnect client, she enters her username and password and successfully a

  • Camera lag after Mountain Lion upgrade

    I've noticed a distinct lag in the built-in camera (say when using PhotoBooth) after the upgrade to OS X 10.8.  Before the upgrade I was able to record video usign PhotoBooth nearly perfectly - now there is a lag between the audio and the video.  Eve

  • My Code Samples Don't Always Display

    I have table that contain code samples. The help system renders everything except the code. If I reload, the code appears: http://help.marketbright.com/index.html#adding_tracking_codes.htm What's the proper way of "wrapping" code samples so that it's

  • Explorer.exe Application Error on shut down

    On shut down I am getting the following explorer.exe application error: The exception unknown software exception (0xc000042) occurred in the application at location 0x89087e03.   Click on OK to terminate the program How do I fix it?