
#ifndef PROCESS_H
#define PROCESS_H

#include <stdio.h>
#include <stdlib.h>

class Process
{
	int argsNum, envsNum;
	char *args[256];
	char *envs[10];
	pid_t pid;
	int result;
	int outPipe[2], inPipe[2], errPipe[2];
	class LineReader *inStream;
	FILE *protoStream;
public:
	Process(const char *fileName);
	~Process();
	void addArg(const char *format, ...);
	void closePipeToChild();
	int getErrorStream();
	int getInputStream();
	pid_t getPID() { return pid; }
	int getResult();
	int isLineAvailable();
	int read(char *buf, int count);
	virtual const char *readLine();
	int run();
	void select();
	void setInputStream(int fd);
	void setProtoFile(const char *fileName);
	void show();
	void start(const char *workDirName = NULL, int splitOut = 0);
	void terminate();
	const char *toString(char *str);
	int write(const char *buf, int count);

private:
	void closePipes();
};

#endif
