Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "rospack/rospack_backcompat.h"
00029 #include "rospack/rospack.h"
00030 #include "rospack_cmdline.h"
00031
00032 #include <boost/algorithm/string.hpp>
00033 #include <string.h>
00034 #include <stdio.h>
00035 #include <errno.h>
00036
00037 namespace rospack
00038 {
00039
00040 int
00041 ROSPack::run(int argc, char** argv)
00042 {
00043 rospack::Rospack rp;
00044 output_.clear();
00045 bool success = rospack::rospack_run(argc, argv, rp, output_);
00046 if(!success)
00047 {
00048 fprintf(stderr, "[librospack]: error while executing command\n");
00049 return 1;
00050 }
00051 return 0;
00052 }
00053
00054 int
00055 ROSPack::run(const std::string& cmd)
00056 {
00057
00058 std::string full_cmd = std::string("rospack ") + cmd;
00059
00060 int argc;
00061 char** argv;
00062 std::vector<std::string> full_cmd_split;
00063 boost::split(full_cmd_split, full_cmd,
00064 boost::is_any_of(" "),
00065 boost::token_compress_on);
00066 argc = full_cmd_split.size();
00067 argv = new char*[argc];
00068 int i = 0;
00069 for(std::vector<std::string>::const_iterator it = full_cmd_split.begin();
00070 it != full_cmd_split.end();
00071 ++it)
00072 {
00073 argv[i] = new char[it->size()+1];
00074 memset(argv[i], 0, it->size()+1);
00075 memcpy(argv[i], it->c_str(), it->size());
00076 i++;
00077 }
00078
00079 int ret = run(argc, argv);
00080
00081 for(int i=0; i<argc; i++)
00082 delete[] argv[i];
00083 delete[] argv;
00084
00085 return ret;
00086 }
00087
00088 }