blob: d4692a1cf70e55ef4ab36ab136f27abda5c5a3ae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#include <unistd.h>
#include "Action.h"
#include "Handle.h"
#include "HttpServ.h"
#include "Socket.h"
#include "config.h"
#include "Message.h"
#include "Menu.h"
#include "Exceptions.h"
#include "Form.h"
#include "Confirm.h"
#include "Table.h"
#include "admin.h"
class InPipe : public Handle {
public:
InPipe(int in, int out) : Handle(in), m_out(out) { };
virtual ~InPipe() {}
int GetOut(void) { return m_out; }
virtual bool CanWrite(void) { return false; }
virtual bool CanRead(void) { return true; }
virtual String GetName(void) { return "Input pipe"; }
private:
int m_out;
} * in;
int main(int argc, char ** argv) {
int p[2], c;
if (pipe(p)) {
cerr << "Error creating pipe.\n";
exit(-1);
}
close(1);
dup(p[1]);
in = new InPipe(p[0], p[1]);
String test = "poide\n", r;
cout << test;
cout.flush();
(*in) >> r;
if (r != "poide") {
cerr << "The stdout redirect has failed.\n";
exit(-1);
}
while ((c = getopt(argc, argv, "p:")) != EOF) {
switch (c) {
case 'p':
break;
default:
cerr << "Usage: " << argv[0] << " [-p port]\n";
exit(-1);
}
}
try {
}
catch (GeneralException e) {
cerr << e.GetMsg() << endl;
delete in;
exit(-1);
}
delete in;
exit(0);
}
|