-1

My os is MAC OS 10.11.3.

I using Spark as our IM(Instant messaging),but when the IM log out,IM give an error,said:

java.io.IOException: Cannot run program "open": error=2, No such file or directory .

But when Eclipse runs it, it worked well,and when I wrapped it a mac package and installed it and run it, click "log out" button, it throws errors.

In program, when I log out,I launch a new IM,meanwhile,I killed the old IM application.

Furthermore,in terminal,no matter what I run how many times “open -a Spark”,it just open the same IM,

The source as follows:

public boolean restartApplicationWithScript() {
    String command = null;
    try {
        if (Spark.isMac()) {
            command = "open -a " + Default.getString(Default.SHORT_NAME);
        }

        String commands[] = {"open", "/Applications/Spark.app"}; 
        Runtime.getRuntime().exec(commands);

        System.exit(0);
        return true;
    } catch (IOException e) {
        Log.error("Error trying to restart application with script", e);
        return false;
    }
}
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245

2 Answers2

0

The exception seems to be saying that it cannot find the open command. That seems a bit odd, since it is a standard MacOS command. So I suspect that the reason that it cannot be found is that it is not on the PATH.

  • Try giving the absolute pathname for the open command. Running which open should tell you what it is.
  • If open is a shell builtin on MacOS, then you will need to create a subshell to run the command.
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Dear Stephen C, thans a lots, i attempted to use the absolute path name ,but does not work,and how i create a subshell to run the command, – hongxing ji Dec 17 '16 at 04:11
  • Before you do that, have you *checked* whether `open` is a shell built-in. If you haven't checked, then you are probably wasting your time running the command in a subshell. – Stephen C Dec 17 '16 at 06:29
  • Dear Stephen C,thanks for your reply, i checked the open is not a shell built-in,used "type open" in shell , and it give me a "open is hashed (/usr/bin/open)" , so i think it not a built-in command , since i "type cd" responded a "cd is a shell builtin" , so , how can i do next, im most grateful for your help – hongxing ji Dec 19 '16 at 02:11
  • i used "enable open" in terminal,it responseed "-bash: enable: open: not a shell builtin",i ensure it not a built-in command,thank you – hongxing ji Dec 19 '16 at 02:18
  • In that case I'm stumped. (And I don't have a Mac to run your code.) – Stephen C Dec 19 '16 at 02:48
0

Thanks for all, i solved it by 2 step : 1, cmdline = { "open", "-na", "Microsoft Excel" }; this add a "n" ,otherwise,it will open the same app 。 2,chmod -R 777 youAppPath,if not do this ,the app can't issue the command