1

I am trying to make a eclipse project in Java to launch commands with some buttons. The libraries of Ros fuerte (These ones i want to use) are correctly installed and concretly i am trying to launch a ros command from a Java File using:

String cmd = "roscore";

Runtime rt = Runtime.getRuntime();

Process p = rt.exec(cmd);

If i launch this command from a current terminal it works, but if i do it from the java file i have a problem because the terminal doesnt recognize the command.

java.io.IOException: Cannot run program "roscore": java.io.IOException: error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:475)
at java.lang.Runtime.exec(Runtime.java:610)
at java.lang.Runtime.exec(Runtime.java:448)
at java.lang.Runtime.exec(Runtime.java:345)
at LaunchTerminal.main(LaunchTerminal.java:24)

I think that i need to add some path or similar but i dont find the information. Does anybody know how to do it?

Thank u.

Fildor
  • 14,510
  • 4
  • 35
  • 67
  • 2
    launch program with absolute path. – Jayan Sep 18 '12 at 08:59
  • possible duplicate of [Execute external program through terminal in Java](http://stackoverflow.com/questions/8751337/execute-external-program-through-terminal-in-java) – codeling Sep 18 '12 at 09:01

2 Answers2

0

only normal commands are possible to execute like rm or cd ... al others must be referenced with full path of context

  • Thank you! Now it works, but the terminal closes when it executes the command. Is it possible to keep it open? – user1679709 Sep 18 '12 at 09:33
  • why you want to keep it open? but here an nice site http://www.java-tips.org/java-se-tips/java.util/from-runtime.exec-to-processbuilder.html – mbraunerDE Sep 18 '12 at 09:44
  • I need it because its a program (master) with whom all the rest ot the "nodes" of Ros are connected, so i need it to be opened. – user1679709 Sep 18 '12 at 11:00
  • is roscore an command which you can use everywhere in the terminal? if yes ... i have no idea why that doesnt work ... else ... you have to use the fully qualified path and name of this script – mbraunerDE Sep 18 '12 at 13:42
0

Do the following if you are using the groovy distribution:

String cmd = "source /opt/ros/groovy/setup.bash && roscore";
Lundin
  • 195,001
  • 40
  • 254
  • 396
fatma
  • 1