command.h

Go to the documentation of this file.
00001 /* -*- Mode: c++ -*- */
00002 /*
00003  *  this is part of Spm
00004  *
00005  *  Copyright (c) 2005 Guillaume Chevallereau
00006  *
00007  *  This program is free software. You can redistribute it and/or modify it 
00008  *  under the terms of the GNU General Public License as published by the 
00009  *  Free Software Foundation. Either version 2 of the license or (at your 
00010  *  option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be usefull but WITHOUT
00013  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
00014  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
00015  *  more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License along 
00018  *  with this program; if not, write to the Free Software Foundation, Inc., 
00019  *  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
00020  */
00021 #ifndef __COMMAND_H__
00022 #define __COMMAND_H__
00023 
00024 #include <string>
00025 #include <istream>
00026 #include <ostream>
00027 #include <vector>
00028 #include <map>
00029 #include <boost/filesystem/path.hpp>
00030 
00031 namespace Spm
00032 {
00033   namespace Util
00034   {
00039     class Command
00040     {
00041     private :
00042       std::string __cmd;
00043       boost::filesystem::path __workingDir;
00044       std::vector<std::string> args;
00045       std::map<std::string,
00046                std::string> envs;
00047       unsigned int pid;
00048       int retVal;
00049       
00050 
00051     public:
00055       Command (const std::string & cmd);
00056 
00059       Command ();
00060 
00061       void setCommand (const std::string & cmd);
00062       
00067       void add (const std::string & arg);
00068 
00074       void add (const std::string & var,
00075                 const std::string & val);
00076       
00082       bool execSync (std::string & out,
00083                      std::string & err);
00084       
00091       bool execASync (int & out,
00092                       int & err,
00093                       int & in);                      
00094       
00098       const boost::filesystem::path & getWorkingDir ();
00099 
00103       void setWorkingDir (const boost::filesystem::path & dir);
00104 
00108       unsigned int getPid ();
00109 
00113       int getReturnValue ();
00114 
00115       /*
00116          \brief Execute a simple command
00117          \param cmd The command to execute
00118          \param out The command output 
00119          \param err The command error
00120          \return the value returned by the execution of the command
00121        */
00122       static int exec (const std::string & cmd,
00123                        std::string & out,
00124                        std::string & err);
00125       
00130       bool wait ();
00131       
00132       /*
00133         \brief Send a signal to the command
00134         \param signal the signal to send (KILL by default)
00135        */
00136       void kill (int signal = 9);
00137     };
00138   }
00139 }
00140 #endif

Generated on Wed Jul 4 15:27:21 2007 for libSpm by  doxygen 1.4.6