summaryrefslogtreecommitdiff
path: root/competition/process.h
blob: ddd80b9bf2dee75cdceae9fffb82a9f810ed0f3e (plain)
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
#pragma once

#include <string>
#include <optional>
#include <string_view>
#include <unistd.h>

using namespace std;


class Process {
	string execname;
	optional<string> stderrRedirect;
	pid_t pid = -1;
	int infd = -1, outfd = -1;

	string readBuf;

public:
	Process(const string_view execname);

	void redirectStderr(const string_view fname);

	void run();
	void wait();
	void stop();
	void unStop();
	void terminate();

	bool writeLine(const string_view line);
	optional<string> readLine();
};