Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
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

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

Definition at line 18 of file JProcess.cc.

19 {
20  using namespace std;
21 
22  string command;
23  bool use_cin;
24  bool revert;
25 
26  try {
27 
28  JParser<> zap("Example for testing inter-process communication.");
29 
30  zap['c'] = make_field(command);
31  zap['C'] = make_field(use_cin);
32  zap['r'] = make_field(revert);
33 
34  zap(argc, argv);
35  }
36  catch(const exception &error) {
37  FATAL(error.what() << endl);
38  }
39 
40 
41 
42  using namespace JPP;
43 
44  try {
45 
46  JProcess process(command);
47 
48  if (!use_cin) {
49 
50  istream in(process.getInputStreamBuffer());
51 
52  for (string buffer; getline(in, buffer); ) {
53  cout << buffer << endl;
54  }
55 
56  } else {
57 
58  ostream out(process.getOutputStreamBuffer());
59  istream in (process.getInputStreamBuffer());
60 
61  for (string buffer; getline(cin, buffer) && buffer != ""; ) {
62 
63  out << buffer << endl;
64 
65  getline(in, buffer);
66 
67  if (revert) {
68  reverse(buffer.begin(), buffer.end());
69  }
70 
71  cout << buffer << endl;
72  }
73  }
74  }
75  catch(const JException& error) {
76  cerr << error.what() << endl;
77  }
78 }
Utility class to parse command line options.
Definition: JParser.hh:1493
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
#define FATAL(A)
Definition: JMessage.hh:67