0

Possible Duplicate:
Execute another jar in a java program

I am making a program that run from a java document, and runs a Java document. I am using windows and

Process pr = Runtime.getRuntime().exec(
   "cmd /c start cmd.exe /c \"cd %appdata%\\.gknl && java -jar launcher.jar\""
);

works for me fine, but on linux,Mac etc it wont work,

Can someone help me to fix the other OS systems?

Note: i already have a check for the OS...

Community
  • 1
  • 1

3 Answers3

0

Linux:

Process pr = Runtime.getRuntime().exec(new String[]{"csh","-c","cd " + appdata +"\.gknl &&  java -jar launcher.jar");
jco.owens
  • 535
  • 2
  • 5
  • 2
    csh is not installed on all Linux systems. I have 4 systems in front of me and I only have it on 1. If you want to be assured that something will work, you use sh. That is on my Ubuntu, both Fedoras, and my Raspian system. – Erik Nedwidek Jan 13 '13 at 22:58
  • I install csh anywhere I have to do work ;) – jco.owens Jan 13 '13 at 23:43
0

In Linux/Unix you want to use sh. This will be linked on most systems to bash, zsh, or csh.

I am 95% sure that sh is also on the Mac, but I'd need to unplug my Raspberry Pi and put everything back into my Mac Mini to verify.

Erik Nedwidek
  • 6,134
  • 1
  • 25
  • 25
0

cmd.exe is the Windows shell executable, you will need to use one of the Linux/Mac shells:

ProcessBuilder pb = new ProcessBuilder(
        "sh", "-c",
        "cd $appdata/.gknl && java -jar launcher.jar");
pb.start();

If launcher.jar is on the classpath, it should be possible to launch the main application class from the calling application however without using Process/ProcessBuilder.

Reimeus
  • 158,255
  • 15
  • 216
  • 276