Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JProcess.cc File Reference

Example for testing inter-process communication. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include "JSystem/JProcess.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Detailed Description

Example for testing inter-process communication.

Author
mdejong

Definition in file JProcess.cc.

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 18 of file JProcess.cc.

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}
#define FATAL(A)
Definition JMessage.hh:67
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
General exception.
Definition JException.hh:24
virtual const char * what() const override
Get error message.
Definition JException.hh:64
Utility class to parse command line options.
Definition JParser.hh:1698
Streaming of input and output from Linux command.
Definition JProcess.hh:30
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition JString.hh:478
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).