|
a/src/utils/execmd.h |
|
b/src/utils/execmd.h |
1 |
#ifndef _EXECMD_H_INCLUDED_
|
1 |
#ifndef _EXECMD_H_INCLUDED_
|
2 |
#define _EXECMD_H_INCLUDED_
|
2 |
#define _EXECMD_H_INCLUDED_
|
3 |
/* @(#$Id: execmd.h,v 1.2 2005-03-17 14:02:06 dockes Exp $ (C) 2004 J.F.Dockes */
|
3 |
/* @(#$Id: execmd.h,v 1.3 2005-11-18 13:52:48 dockes Exp $ (C) 2004 J.F.Dockes */
|
4 |
|
4 |
|
5 |
#include <string>
|
5 |
#include <string>
|
6 |
#include <list>
|
6 |
#include <list>
|
7 |
|
7 |
|
|
|
8 |
/**
|
|
|
9 |
Execute command possibly taking both input and output (will do
|
|
|
10 |
asynchronous io as appropriate for things to work).
|
|
|
11 |
*/
|
8 |
class ExecCmd {
|
12 |
class ExecCmd {
|
9 |
public:
|
13 |
public:
|
10 |
// ExecCmd() : argv(0) {};
|
14 |
/**
|
11 |
// ~ExeCmd() {delete [] argv;}
|
15 |
* Execute command. Both input and output can be specified, and
|
|
|
16 |
* asynchronous io is used to prevent blocking. This wont work if
|
|
|
17 |
* input and output need to be synchronized (ie: Q/A), but ok for
|
|
|
18 |
* filtering.
|
|
|
19 |
* @param cmd the program to execute. This must be an absolute file name
|
|
|
20 |
* or exist in the PATH.
|
|
|
21 |
* @param args the argument list (NOT including argv[0]).
|
|
|
22 |
* @param input Input to send to the command.
|
|
|
23 |
* @param output Output from the command.
|
|
|
24 |
* @return the exec ouput status (0 if ok).
|
|
|
25 |
*/
|
12 |
int doexec(const std::string &cmd, const std::list<std::string>& a,
|
26 |
int doexec(const std::string &cmd, const std::list<std::string>& args,
|
13 |
const std::string *input = 0,
|
27 |
const std::string *input = 0,
|
14 |
std::string *output = 0);
|
28 |
std::string *output = 0);
|
|
|
29 |
/**
|
|
|
30 |
* Add/replace environment variable before executing command. This should
|
|
|
31 |
* be called before doexec of course.
|
|
|
32 |
* @param envassign an environment assignment string (name=value)
|
|
|
33 |
*/
|
|
|
34 |
void putenv(const std::string &envassign);
|
|
|
35 |
|
|
|
36 |
private:
|
|
|
37 |
std::list<std::string> env;
|
15 |
};
|
38 |
};
|
16 |
|
39 |
|
17 |
|
40 |
|
18 |
#endif /* _EXECMD_H_INCLUDED_ */
|
41 |
#endif /* _EXECMD_H_INCLUDED_ */
|