Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6754469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:17:00+00:00 2026-05-26T13:17:00+00:00

I´m using Mac OS Lion, with java version 1.6.0_26 I’m making a small app

  • 0

I´m using Mac OS Lion, with java version 1.6.0_26

I’m making a small app for Mac in Java with a main menu for the user, so he can choose several options.

One of them is install an app using a .pkg

Everything was working fine with these commands:

File instFolder = new File(System.getProperty("user.dir") + "/foldername/appInstaller.pkg");
String s = "open "+ instFolder.toString();
Process p = Runtime.getRuntime().exec(s);

Then I realized that there is a problem when foldername has spaces or if I copy this java file with the needed subfolders to a USB pen drive with “NO NAME” as name (or some name with spaces).

Because s will become something like:

open /Volumes/NO NAME/foldername/appInstaller.pkg
or
open /Users/user1/Desktop/folder name/appInstaller.pkg

So when you run the p process, the command will finish where the first space appears on the path

open /Volumes/NO
or
open /Users/user1/Desktop/folder

To try to fix this I changed the s definition for something like this:

String s = "open "+ "\"" + instFolder.toString() + "\"";

It stopped working fine. The strange thing is that if i copy the s value (after creating the s variable) and paste it in the terminal it works:

open “/Users/user1/Desktop/folder name/appInstaller.pkg”

but running it from Java it does’t work.

Could you help me, please?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:17:01+00:00Added an answer on May 26, 2026 at 1:17 pm

    In order to properly escape arguments, you can use the following:

    Runtime.getRuntime().exec(new String[] { "open", instFolder.toString() });
    

    Though I would probably to use the more modern ProcessBuilder:

    ProcessBuilder pb = new ProcessBuilder("open", instFolder.toString());
    Process p = pb.start();
    int exitCode = p.waitFor();
    

    Though this may be worth a read depending on what you want to do with the processes output.

    Note: edited to reflect question in comment

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using mac os lion with the latest xcode version. I installed phonegap from
I'm using Mac Lion 10.7.1, MacVim Snapshot 61, Vim version 7.3 I want to
I want to create a Java application bundle for Mac without using Mac. According
How can I connect to a remote SQL server using Mac OS X? I
Today, I ran into this weird problem with a user using Mac OS X.
I'm using Mac OS X Snow Leopard and i can not install PIL 1.1.6.
using Mac OSX, how can I add a device into J2ME Emulator? I have
I'm trying to install GDAL 1.7.1 on Mac OS X Lion using: python setup.py
I'm using Mac OSX Lion and I would like to have a script that
I am using Mac OS X Lion 10.7.2. I am trying to download and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.