1 |
#include "SubPipe.h" |
2 |
|
3 |
SubPipe::SubPipe(string command){ |
4 |
|
5 |
p = new iopipestream(command.c_str()); |
6 |
pid = (*p).pid(); |
7 |
|
8 |
} // subPipe |
9 |
|
10 |
|
11 |
int SubPipe::getLine(string * fillme){ |
12 |
|
13 |
int bob = 2048; |
14 |
char input[bob]; |
15 |
|
16 |
if ( (*p).getline(input, bob-1) ){ |
17 |
string sinput = input; |
18 |
*fillme = sinput; |
19 |
return 0; |
20 |
} else { |
21 |
return 1; |
22 |
} // if |
23 |
|
24 |
} // getLine |
25 |
|
26 |
SubPipe::~SubPipe(){ |
27 |
|
28 |
// wait for process to finish first |
29 |
waitpid(pid , 0, 0); |
30 |
// remove all pointers to it, free up the memory so |
31 |
// we can reclaim the file handles back |
32 |
delete p; |
33 |
|
34 |
} // ~SubPipe |
35 |
|