-4

I have a java application, which will start another Java program by itself. I do it by using

Runtime.getRuntime().exec("/usr/lib/jvm/java-7-oracle/jre/bin/java -Dfile.encoding=UTF-8 -cp /home/AL/Dropbox/Distributed\ Systems/Project/distributedIM/DS/lib/derbyclient.jar:/home/AT/Dropbox/Distributed\ Systems/Project/distributedIM/DS/lib/gson-2.2.4.jar:/home/AT/Dropbox/Distributed\ Systems/Project/distributedIM/DS/build/classes com.myim.client.main.StartClient");

It works well on mac os 10.9, but when I try on Linux Mint, nothing happened.... I
I'm really dont understand why, can someone help me ?
Thank you very much.

Xitrum
  • 7,765
  • 26
  • 90
  • 126
  • 1
    What's the actual command line you're using? What error message or exception do you get? – John Kugelman Oct 30 '13 at 21:12
  • Related: http://stackoverflow.com/q/2876964, especially the top answer. – Robert Harvey Oct 30 '13 at 21:14
  • Why not use a `ClassLoader` directly to start a Java application from Java? – Boris the Spider Oct 30 '13 at 21:23
  • Read (and implement) *all* the recommendations of [When Runtime.exec() won't](http://www.javaworld.com/jw-12-2000/jw-1229-traps.html). That might solve the problem. If not, it should provide more information as to the reason it failed. Then ignore that it refers to `exec` and build the `Process` using a `ProcessBuilder`. Also break a `String arg` into `String[] args` to account for arguments which themselves contain spaces. – Andrew Thompson Oct 30 '13 at 23:43

2 Answers2

1

try something like

String[] cmd = new String[] {"/bin/bash", "-c", "ps"}
Runtime.getRuntime().exec(cmd);

in Linux. Replace ps with the command you try to execute in your terminal. You can even use pipe and filters: "ps -fe | grep bash" within your command

Roman Vottner
  • 12,213
  • 5
  • 46
  • 63
0

As far as I know, commandline is not an existing Unix program. If you replaced the real command in your question by commandline, then the problem is most likely going to be that the application you are trying to invoke does not exist in Linux.

Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287