Jpp  15.0.4
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
JSYSTEM::JProcess Class Reference

Streaming of input and output from Linux command. More...

#include <JProcess.hh>

Inheritance diagram for JSYSTEM::JProcess:
JSYSTEM::JShell

Public Member Functions

 JProcess ()
 Default constructor. More...
 
 JProcess (const std::string &command)
 Constructor. More...
 
 ~JProcess ()
 Destructor. More...
 
JFileInputStreamBuffergetInputStreamBuffer (const std::size_t size=65536)
 Get pointer to input stream buffer connected to the normal output stream. More...
 
JFileInputStreamBuffergetErrorStreamBuffer (const std::size_t size=65536)
 Get pointer to input stream buffer connected to the error output stream. More...
 
JFileOutputStreamBuffergetOutputStreamBuffer (const std::size_t size=65536)
 Get pointer to output stream buffer connected to the normal input stream. More...
 

Protected Member Functions

void execute (const char *path, const char *arg0, const char *arg1=(char *) NULL, const char *arg2=(char *) NULL, const char *arg3=(char *) NULL, const char *arg4=(char *) NULL, const char *arg5=(char *) NULL, const char *arg6=(char *) NULL, const char *arg7=(char *) NULL, const char *arg8=(char *) NULL, const char *arg9=(char *) NULL)
 Execute command. More...
 

Protected Attributes

int out
 
int err
 
int in
 

Private Attributes

JFileInputStreamBuffergOut
 
JFileInputStreamBuffergErr
 
JFileOutputStreamBuffergIn
 

Detailed Description

Streaming of input and output from Linux command.

Definition at line 29 of file JProcess.hh.

Constructor & Destructor Documentation

JSYSTEM::JProcess::JProcess ( )
inline

Default constructor.

This constructor starts an interactive shell.

Definition at line 36 of file JProcess.hh.

36  :
37  out (-1),
38  err (-1),
39  in (-1),
40  gOut(NULL),
41  gErr(NULL),
42  gIn (NULL)
43  {
44  execute("/bin/tcsh", "tcsh", "-i", "-f");
45  }
void execute(const char *path, const char *arg0, const char *arg1=(char *) NULL, const char *arg2=(char *) NULL, const char *arg3=(char *) NULL, const char *arg4=(char *) NULL, const char *arg5=(char *) NULL, const char *arg6=(char *) NULL, const char *arg7=(char *) NULL, const char *arg8=(char *) NULL, const char *arg9=(char *) NULL)
Execute command.
Definition: JProcess.hh:143
JFileOutputStreamBuffer * gIn
Definition: JProcess.hh:209
JFileInputStreamBuffer * gOut
Definition: JProcess.hh:207
JFileInputStreamBuffer * gErr
Definition: JProcess.hh:208
JSYSTEM::JProcess::JProcess ( const std::string &  command)
inline

Constructor.

Parameters
commandLinux command

Definition at line 53 of file JProcess.hh.

53  :
54  out (-1),
55  err (-1),
56  in (-1),
57  gOut(NULL),
58  gErr(NULL),
59  gIn (NULL)
60  {
61  execute("/bin/tcsh", "tcsh", "-f", "-c", command.c_str());
62  }
void execute(const char *path, const char *arg0, const char *arg1=(char *) NULL, const char *arg2=(char *) NULL, const char *arg3=(char *) NULL, const char *arg4=(char *) NULL, const char *arg5=(char *) NULL, const char *arg6=(char *) NULL, const char *arg7=(char *) NULL, const char *arg8=(char *) NULL, const char *arg9=(char *) NULL)
Execute command.
Definition: JProcess.hh:143
JFileOutputStreamBuffer * gIn
Definition: JProcess.hh:209
JFileInputStreamBuffer * gOut
Definition: JProcess.hh:207
JFileInputStreamBuffer * gErr
Definition: JProcess.hh:208
JSYSTEM::JProcess::~JProcess ( )
inline

Destructor.

Definition at line 68 of file JProcess.hh.

69  {
70  close(err);
71  close(out);
72  close(in);
73 
74  if (gOut != NULL) { delete gOut; }
75  if (gErr != NULL) { delete gErr; }
76  if (gIn != NULL) { delete gIn; }
77  }
void close(std::istream *pf)
Close file.
Definition: JeepToolkit.hh:346
JFileOutputStreamBuffer * gIn
Definition: JProcess.hh:209
JFileInputStreamBuffer * gOut
Definition: JProcess.hh:207
JFileInputStreamBuffer * gErr
Definition: JProcess.hh:208

Member Function Documentation

JFileInputStreamBuffer* JSYSTEM::JProcess::getInputStreamBuffer ( const std::size_t  size = 65536)
inline

Get pointer to input stream buffer connected to the normal output stream.

Parameters
sizesize of internal buffers
Returns
pointer input stream buffer

Definition at line 86 of file JProcess.hh.

87  {
88  if (gOut == NULL) {
89  gOut = new JFileInputStreamBuffer(out, size);
90  }
91 
92  return gOut;
93  }
JFileInputStreamBuffer * gOut
Definition: JProcess.hh:207
JFileInputStreamBuffer* JSYSTEM::JProcess::getErrorStreamBuffer ( const std::size_t  size = 65536)
inline

Get pointer to input stream buffer connected to the error output stream.

Parameters
sizesize of internal buffers
Returns
pointer to input stream buffer

Definition at line 102 of file JProcess.hh.

103  {
104  if (gErr == NULL) {
105  gErr = new JFileInputStreamBuffer(err, size);
106  }
107 
108  return gErr;
109  }
JFileInputStreamBuffer * gErr
Definition: JProcess.hh:208
JFileOutputStreamBuffer* JSYSTEM::JProcess::getOutputStreamBuffer ( const std::size_t  size = 65536)
inline

Get pointer to output stream buffer connected to the normal input stream.

Parameters
sizesize of internal buffers
Returns
pointer to output stream buffer

Definition at line 118 of file JProcess.hh.

119  {
120  if (gIn == NULL) {
121  gIn = new JFileOutputStreamBuffer(in, size);
122  }
123 
124  return gIn;
125  }
JFileOutputStreamBuffer * gIn
Definition: JProcess.hh:209
void JSYSTEM::JProcess::execute ( const char *  path,
const char *  arg0,
const char *  arg1 = (char*) NULL,
const char *  arg2 = (char*) NULL,
const char *  arg3 = (char*) NULL,
const char *  arg4 = (char*) NULL,
const char *  arg5 = (char*) NULL,
const char *  arg6 = (char*) NULL,
const char *  arg7 = (char*) NULL,
const char *  arg8 = (char*) NULL,
const char *  arg9 = (char*) NULL 
)
inlineprotected

Execute command.

Parameters
pathpath
arg0comma separted argument list
arg1comma separted argument list
arg2comma separted argument list
arg3comma separted argument list
arg4comma separted argument list
arg5comma separted argument list
arg6comma separted argument list
arg7comma separted argument list
arg8comma separted argument list
arg9comma separted argument list

Definition at line 143 of file JProcess.hh.

154  {
155  int pipe_stdin [2];
156  int pipe_stdout[2];
157  int pipe_stderr[2];
158 
159  if (pipe(pipe_stdin)) { throw JPipeOpenException("Error at pipe of standard input."); }
160  if (pipe(pipe_stdout)) { throw JPipeOpenException("Error at pipe of standard output."); }
161  if (pipe(pipe_stderr)) { throw JPipeOpenException("Error at pipe of standard error."); }
162 
163  const pid_t pid = fork();
164 
165  if (pid < 0)
166 
167  // error
168 
169  throw JForkException("JProcess::fork() failed");
170 
171  else if (pid == 0) {
172 
173  // child
174 
175  close(pipe_stdin [1]);
176  if (dup2 (pipe_stdin [0], STDIN_FILENO) == -1) { JSystemException("dup2-stdin"); }
177 
178  close(pipe_stdout[0]);
179  if (dup2 (pipe_stdout[1], STDOUT_FILENO) == -1) { JSystemException("dup2-stdout"); }
180 
181  close(pipe_stdout[0]);
182  if (dup2 (pipe_stdout[1], STDERR_FILENO) == -1) { JSystemException("dup2-stderr"); }
183 
184  execl(path, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, (char*) NULL);
185 
186  throw JSystemException(path);
187 
188  } else {
189 
190  // parent
191 
192  in = pipe_stdin [1];
193  out = pipe_stdout[0];
194  err = pipe_stderr[0];
195 
196  close(pipe_stdin [0]);
197  close(pipe_stdout[1]);
198  close(pipe_stderr[1]);
199  }
200  }
$WORKDIR driver txt done cat $WORKDIR driver txt<< EOFprocess ${DATAFILTER}$FILTER_HOST csh-c '(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&JDataFilter-H\$SERVER\$-M\$LOGGER\$-d $DEBUG-u ${DATAFILTER}-P $PORT</dev/null > &/dev/null)&';process ${DATAWRITER}$WRITER_HOST csh-c '(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&JDataWriter-H\$SERVER\$-M\$LOGGER\$-d $DEBUG-u ${DATAWRITER}</dev/null > &/dev/null)&';print enterevent ev_init{RC_CMD}event ev_reset{RC_CMD}event ev_init{RC_CMD}event ev_configure{RC_DFLTR%<$WORKDIR/ev_configure_datafilter.txt > RC_DOM<$WORKDIR/ev_configure_domsimulator.txt > RC_DWRT path
void close(std::istream *pf)
Close file.
Definition: JeepToolkit.hh:346

Member Data Documentation

int JSYSTEM::JProcess::out
protected

Definition at line 202 of file JProcess.hh.

int JSYSTEM::JProcess::err
protected

Definition at line 203 of file JProcess.hh.

int JSYSTEM::JProcess::in
protected

Definition at line 204 of file JProcess.hh.

JFileInputStreamBuffer* JSYSTEM::JProcess::gOut
private

Definition at line 207 of file JProcess.hh.

JFileInputStreamBuffer* JSYSTEM::JProcess::gErr
private

Definition at line 208 of file JProcess.hh.

JFileOutputStreamBuffer* JSYSTEM::JProcess::gIn
private

Definition at line 209 of file JProcess.hh.


The documentation for this class was generated from the following file: