00001
00002
00003
00004
00005
00006
00007 #include "ComPlusPlus/Launch.h"
00008 #include "SysPlusPlus/ComException.h"
00009 #include "SysPlusPlus/Tools.h"
00010 #include <unistd.h>
00011 #include <string.h>
00012
00016 compp::Launch::Launch( const std::string & cmd ) : Clone (cmd) {
00017
00018 Command = cmd;
00019
00020 char *sub, *saveptr ;
00021 int i =0;
00022 char *token, *orig = strdup ( Command.c_str() );
00023
00024 for ( token = orig; ;token = NULL ) {
00025 sub = strtok_r ( token , " ", &saveptr );
00026 if ( NULL != sub )
00027 mArgv [ i ] = strdup(sub);
00028 else
00029 mArgv [ i ] = NULL;
00030
00031 if (sub == NULL) {
00032 break;
00033 }
00034 ++i;
00035 }
00036
00037 }
00038
00042 compp::Launch::~Launch() {
00043
00044 }
00045
00046 int compp::Launch::Spawn( ) {
00047
00048 if ( false == syspp::Tools::IsExecutable ( mArgv[0] ) ) {
00049 std::string errstr= "Cannot Launch: execv() failed: " ;
00050 errstr += Command;
00051 errstr += " err = ";
00052 errstr += strerror ( errno );
00053 throw syspp::ComException ( errstr.c_str() );
00054 }
00055 Start();
00056 return 0;
00057 }
00058
00059 int compp::Launch::Run ( ) {
00060
00061 execv ( mArgv[0], mArgv ) ;
00062 std::string errstr= "Cannot Launch ( execv() failed: " ;
00063 errstr += Command;
00064 errstr += " err = ";
00065 errstr += strerror ( errno );
00066
00067 throw syspp::ComException ( errstr.c_str() );
00068
00069 return -1;
00070 }
00071
00072 void compp::Launch::SetCommand (const std::string &cmdargs) {
00073
00074 this->Command = cmdargs;
00075
00076 }