Jpp  17.3.0-rc.2
the software that should make you happy
 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  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 }
Utility class to parse command line options.
Definition: JParser.hh:1517
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
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
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46