| 1 |
#ifndef __PT_PROCESS_H |
| 2 |
#define __PT_PROCESS_H |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifdef WIN32 |
| 18 |
#include <windows.h> |
| 19 |
#endif |
| 20 |
#include <stdio.h> |
| 21 |
|
| 22 |
class CPtProcess { |
| 23 |
public: |
| 24 |
|
| 25 |
CPtProcess(); |
| 26 |
virtual ~CPtProcess(); |
| 27 |
|
| 28 |
FILE * popen (const char *cmd, const char *mode="r"); |
| 29 |
FILE * fopen (const char *file, const char *mode="r"); |
| 30 |
|
| 31 |
int close(); |
| 32 |
|
| 33 |
bool is_open() const { return _fpt!=NULL ? true : false ;} |
| 34 |
FILE * desc() const { return _fpt;} |
| 35 |
|
| 36 |
char * get_line(char * line, size_t s) const { |
| 37 |
return _fpt ? fgets(line, s, _fpt) : NULL; |
| 38 |
} |
| 39 |
|
| 40 |
#ifdef WIN32 |
| 41 |
public: |
| 42 |
static bool createPipe(HANDLE * h, BOOL bInheritHnd=TRUE); |
| 43 |
|
| 44 |
protected: |
| 45 |
HANDLE pin[2], pout[2], perr[2]; |
| 46 |
char ptmode; |
| 47 |
PROCESS_INFORMATION pi; |
| 48 |
STARTUPINFO si; |
| 49 |
private: |
| 50 |
FILE * freeHandles(); |
| 51 |
static void clean_close(HANDLE& h); |
| 52 |
#endif |
| 53 |
|
| 54 |
protected: |
| 55 |
FILE * _fpt; |
| 56 |
}; |
| 57 |
|
| 58 |
#endif |
| 59 |
|