Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JProcess.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <iomanip>
5#include <algorithm>
6
7#include "JSystem/JProcess.hh"
8#include "Jeep/JParser.hh"
9#include "Jeep/JMessage.hh"
10
11
12/**
13 * \file
14 *
15 * Example for testing inter-process communication.
16 * \author mdejong
17 */
18int main(int argc, char* argv[])
19{
20 using namespace std;
21 using namespace JPP;
22
23 string command;
24 bool use_cin;
25 bool revert;
26
27 try {
28
29 JParser<> zap("Example for testing inter-process communication.");
30
31 zap['c'] = make_field(command);
32 zap['C'] = make_field(use_cin);
33 zap['r'] = make_field(revert);
34
35 zap(argc, argv);
36 }
37 catch(const exception &error) {
38 FATAL(error.what() << endl);
39 }
40
41
42 try {
43
44 JProcess process(command);
45
46 if (!use_cin) {
47
48 istream in(process.getInputStreamBuffer());
49
50 for (string buffer; getline(in, buffer); ) {
51 cout << buffer << endl;
52 }
53
54 } else {
55
56 ostream out(process.getOutputStreamBuffer());
57 istream in (process.getInputStreamBuffer());
58
59 for (string buffer; getline(cin, buffer) && buffer != ""; ) {
60
61 out << buffer << endl;
62
63 getline(in, buffer);
64
65 if (revert) {
66 reverse(buffer.begin(), buffer.end());
67 }
68
69 cout << buffer << endl;
70 }
71 }
72 }
73 catch(const JException& error) {
74 cerr << error.what() << endl;
75 }
76}
General purpose messaging.
#define FATAL(A)
Definition JMessage.hh:67
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
int main(int argc, char *argv[])
Definition JProcess.cc:18
General exception.
Definition JException.hh:24
Utility class to parse command line options.
Definition JParser.hh:1698
Streaming of input and output from Linux command.
Definition JProcess.hh:30
JFileInputStreamBuffer * getInputStreamBuffer(const std::size_t size=65536)
Get pointer to input stream buffer connected to the normal output stream.
Definition JProcess.hh:86
JFileOutputStreamBuffer * getOutputStreamBuffer(const std::size_t size=65536)
Get pointer to output stream buffer connected to the normal input stream.
Definition JProcess.hh:118
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).