tjprocess.h
1 /***************************************************************************
2  tjprocess.h - description
3  -------------------
4  begin : Sat May 5 2007
5  copyright : (C) 2000-2015 by Thies H. Jochimsen
6  email : thies@jochimsen.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef TJPROCESS_H
19 #define TJPROCESS_H
20 
21 #include <tjutils/tjstring.h>
22 #include <tjutils/tjarray.h>
23 
29 
31 // for debugging
32 class ProcessComponent {
33  public:
34  static const char* get_compName();
35 };
36 
38 
39 
43 class Process {
44 
45  public:
46 
50  Process() {reset();}
51 
59  bool start(const STD_string& cmdline, bool block_till_finished=false, bool log_std_streams=true);
60 
66  bool finished(int& proc_return_value, STD_string& stdout_result, STD_string& stderr_result, bool block_till_finished=false);
67 
73  bool finished(int& proc_return_value, bool block_till_finished=false);
74 
78  bool kill(const svector& extra_kill=svector());
79 
84  static int system(const STD_string& cmdline, STD_string& stdout_result, STD_string& stderr_result);
85 
86 
87  // Comparison operators for list of processes with STL replacement
88  bool operator == (const Process& op) const {return pid==op.pid;}
89  bool operator < (const Process& op) const {return pid!=op.pid;}
90  bool operator != (const Process& op) const {return !(*this==op);}
91 
92  private:
93 
94  static bool read_pipe(int fd, STD_string& result);
95  void reset() {pid=0; stdout_child=-1; stderr_child=-1;}
96 
97  int pid;
98  int stdout_child;
99  int stderr_child;
100 };
101 
102 
103 
106 #endif
bool operator==(const TinyVector< T, N_rank > &t1, const TinyVector< T, N_rank > &t2)
Definition: utils.h:129
bool operator!=(const TinyVector< T, N_rank > &t1, const TinyVector< T, N_rank > &t2)
Definition: utils.h:139
Process()
Definition: tjprocess.h:50
bool operator<(const STD_complex &c1, const STD_complex &c2)
Definition: tjcomplex.h:61