RosUtilities.java
Go to the documentation of this file.
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         
00026             Process p = Runtime.getRuntime().exec("rospack find " + pkg);
00027             
00028             if(p.waitFor()==127) {
00029             //  throw new RuntimeException("External program 'rospack' not found");
00030             }
00031 
00032             BufferedReader out = new BufferedReader(new InputStreamReader(p.getInputStream()));
00033             BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream()));
00034 
00035             if ((path = out.readLine()) != null){
00036                 ;//System.out.println("Package: " + pkg + ", Path: " + path);                    
00037             } else {
00038                 
00039                 // print error output
00040                 String l = null;
00041                 while ( (l = err.readLine()) != null)
00042                     System.out.println(l);
00043                 
00044                 ;//System.out.println("Package: " + pkg + ", Error: package not found!");
00045             }
00046         }
00047         catch (Exception e)
00048         {
00049             e.printStackTrace();
00050         }
00051         return path;
00052     }
00053     
00054 
00063     public static String rosrun(String pkg, String binary, String[] arg) throws IOException {
00064 
00065         String handle = null;
00066         try
00067         {
00068                 String args = Joiner.on(" ").join(arg);
00069                 Process p = Runtime.getRuntime().exec("rosrun " + pkg + " " + binary + " " + args);
00070 
00071                 handle = UUID.randomUUID().toString();
00072             processMap.put(handle, p);
00073             
00074         }
00075         catch (Exception e)
00076         {
00077             e.printStackTrace();
00078         }
00079         return handle;
00080     }
00081     
00088     public static void kill(String handle) {
00089         processMap.get(handle).destroy();
00090     }
00091     
00092 }


knowrob_common
Author(s): Moritz Tenorth
autogenerated on Sat Dec 28 2013 17:09:28