|
a/src/utils/execmd.cpp |
|
b/src/utils/execmd.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: execmd.cpp,v 1.6 2005-03-17 14:02:05 dockes Exp $ (C) 2004 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: execmd.cpp,v 1.7 2005-11-18 13:52:48 dockes Exp $ (C) 2004 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
#ifndef TEST_EXECMD
|
4 |
#ifndef TEST_EXECMD
|
5 |
#include <unistd.h>
|
5 |
#include <unistd.h>
|
6 |
#include <sys/types.h>
|
6 |
#include <sys/types.h>
|
7 |
#include <sys/wait.h>
|
7 |
#include <sys/wait.h>
|
|
... |
|
... |
19 |
#include "debuglog.h"
|
19 |
#include "debuglog.h"
|
20 |
|
20 |
|
21 |
using namespace std;
|
21 |
using namespace std;
|
22 |
#define MAX(A,B) (A>B?A:B)
|
22 |
#define MAX(A,B) (A>B?A:B)
|
23 |
|
23 |
|
24 |
int
|
24 |
void ExecCmd::putenv(const string &ea)
|
|
|
25 |
{
|
|
|
26 |
env.push_back(ea);
|
|
|
27 |
}
|
|
|
28 |
|
25 |
ExecCmd::doexec(const string &cmd, const list<string>& args,
|
29 |
int ExecCmd::doexec(const string &cmd, const list<string>& args,
|
26 |
const string *input, string *output)
|
30 |
const string *input, string *output)
|
27 |
{
|
31 |
{
|
28 |
{
|
32 |
{ // Debug and logging
|
29 |
string command = cmd + " ";
|
33 |
string command = cmd + " ";
|
30 |
for (list<string>::const_iterator it = args.begin();it != args.end();
|
34 |
for (list<string>::const_iterator it = args.begin();it != args.end();
|
31 |
it++) {
|
35 |
it++) {
|
32 |
command += "{" + *it + "} ";
|
36 |
command += "{" + *it + "} ";
|
33 |
}
|
37 |
}
|
|
... |
|
... |
184 |
#if 0
|
188 |
#if 0
|
185 |
{int i = 0;cerr << "cmd: " << cmd << endl << "ARGS: " << endl;
|
189 |
{int i = 0;cerr << "cmd: " << cmd << endl << "ARGS: " << endl;
|
186 |
while (argv[i]) cerr << argv[i++] << endl;}
|
190 |
while (argv[i]) cerr << argv[i++] << endl;}
|
187 |
#endif
|
191 |
#endif
|
188 |
|
192 |
|
|
|
193 |
for (it = env.begin(); it != env.end(); it++) {
|
|
|
194 |
::putenv(it->c_str());
|
|
|
195 |
}
|
|
|
196 |
|
189 |
execvp(cmd.c_str(), (char *const*)argv);
|
197 |
execvp(cmd.c_str(), (char *const*)argv);
|
190 |
// Hu ho
|
198 |
// Hu ho
|
191 |
LOGERR(("ExecCmd::doexec: execvp(%s) failed. errno %d\n", cmd.c_str(),
|
199 |
LOGERR(("ExecCmd::doexec: execvp(%s) failed. errno %d\n", cmd.c_str(),
|
192 |
errno));
|
200 |
errno));
|
193 |
exit(128);
|
201 |
exit(128);
|
|
... |
|
... |
222 |
ExecCmd mexec;
|
230 |
ExecCmd mexec;
|
223 |
string input, output;
|
231 |
string input, output;
|
224 |
input = data;
|
232 |
input = data;
|
225 |
string *ip = 0;
|
233 |
string *ip = 0;
|
226 |
//ip = &input;
|
234 |
//ip = &input;
|
|
|
235 |
mexec.putenv("TESTVARIABLE1=TESTVALUE1");
|
|
|
236 |
mexec.putenv("TESTVARIABLE2=TESTVALUE2");
|
|
|
237 |
mexec.putenv("TESTVARIABLE3=TESTVALUE3");
|
|
|
238 |
|
227 |
int status = mexec.doexec(cmd, l, ip, &output);
|
239 |
int status = mexec.doexec(cmd, l, ip, &output);
|
|
|
240 |
|
228 |
fprintf(stderr, "Status: 0x%x\n", status);
|
241 |
fprintf(stderr, "Status: 0x%x\n", status);
|
229 |
cout << "Output:" << output << endl;
|
242 |
cout << "Output:" << output << endl;
|
230 |
exit (status >> 8);
|
243 |
exit (status >> 8);
|
231 |
}
|
244 |
}
|
232 |
#endif // TEST
|
245 |
#endif // TEST
|