wibble  0.1.28
exec.h
Go to the documentation of this file.
00001 #ifndef EXEC_H
00002 #define EXEC_H
00003 
00004 /*
00005  * OO wrapper for execve
00006  *
00007  * Copyright (C) 2003  Enrico Zini <enrico@debian.org>
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00022  */
00023 
00024 #include <wibble/sys/childprocess.h>
00025 
00026 namespace wibble {
00027 namespace sys {
00028 
00033 class Exec : public ChildProcess
00034 {
00035 protected:
00040     virtual int main();
00041 
00042 public:
00043     virtual ~Exec() {}
00044 
00051     std::string pathname;
00052 
00058     std::vector<std::string> args;
00059 
00063     std::vector<std::string> env;
00064 
00069     bool envFromParent;
00070 
00077     bool searchInPath;
00078 
00080     Exec(const std::string& pathname)
00081         : pathname(pathname), envFromParent(true), searchInPath(false)
00082     {
00083         args.push_back(pathname);
00084     }
00085 
00087     void importEnv();
00088 
00090     void exec();
00091 };
00092 
00096 class ShellCommand : public Exec
00097 {
00098 public:
00099     ShellCommand(const std::string& cmd) : Exec("/bin/sh")
00100     {
00101         args.push_back("-c");
00102         args.push_back(cmd);
00103         searchInPath = false;
00104         envFromParent = true;
00105     }
00106 };
00107 
00108 }
00109 }
00110 
00111 // vim:set ts=4 sw=4:
00112 #endif