1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#ifndef __PT_PROCESS_H
#define __PT_PROCESS_H
//========================================================================
// PtProcess.h
//========================================================================
// Portable Process with pipes Handling
// Features easy File and Pipe/Process opening and reading uniformization
// support of read "r" or write "w" popen modes
// Copyright F. Costantini 2006
// Version 1.0
//========================================================================
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License v2 as published
// by the Free Software Foundation.
//========================================================================
#ifdef WIN32
#include <windows.h>
#endif
#include <stdio.h>
class CPtProcess {
public:
// construction / destruction
CPtProcess();
virtual ~CPtProcess();
FILE * popen (const char *cmd, const char *mode="r");
FILE * fopen (const char *file, const char *mode="r");
int close();
bool is_open() const { return _fpt!=NULL ? true : false ;}
FILE * desc() const { return _fpt;}
char * get_line(char * line, size_t s) const {
return _fpt ? fgets(line, s, _fpt) : NULL;
}
#ifdef WIN32
public:
static bool createPipe(HANDLE * h, BOOL bInheritHnd=TRUE);
protected:
HANDLE pin[2], pout[2], perr[2];
char ptmode;
PROCESS_INFORMATION pi;
STARTUPINFO si;
private:
FILE * freeHandles();
static void clean_close(HANDLE& h);
#endif
protected:
FILE * _fpt;
};
#endif
|