00001 package edu.tum.cs.ias.knowrob.utils.ros;
00002
00003 import java.io.*;
00004 import java.util.HashMap;
00005 import java.util.UUID;
00006
00007 import com.google.common.base.Joiner;
00008
00009
00010 public class RosUtilities {
00011
00012 static HashMap<String, Process> processMap = new HashMap<String, Process>();
00013
00020 public static String rospackFind(String pkg) {
00021
00022 String path = null;
00023 try
00024 {
00025 Process p = Runtime.getRuntime().exec("rospack find " + pkg);
00026 p.waitFor();
00027 BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
00028
00029 if ((path = br.readLine()) != null){
00030 ;
00031 }
00032 else
00033 ;
00034 }
00035 catch (Exception e)
00036 {
00037 e.printStackTrace();
00038 }
00039 return path;
00040 }
00041
00042
00051 public static String rosrun(String pkg, String binary, String[] arg) throws IOException {
00052
00053 String handle = null;
00054 try
00055 {
00056 String args = Joiner.on(" ").join(arg);
00057 Process p = Runtime.getRuntime().exec("rosrun " + pkg + " " + binary + " " + args);
00058
00059 handle = UUID.randomUUID().toString();
00060 processMap.put(handle, p);
00061
00062 }
00063 catch (Exception e)
00064 {
00065 e.printStackTrace();
00066 }
00067 return handle;
00068 }
00069
00076 public static void kill(String handle) {
00077 processMap.get(handle).destroy();
00078 }
00079
00080 }