-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpipe_read.cpp
33 lines (27 loc) · 960 Bytes
/
pipe_read.cpp
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
#include <co_async/co_async.hpp>
#include <co_async/std.hpp>
using namespace co_async;
using namespace std::literals;
static Task<Expected<>> amain() {
co_await co_await stdio().putline("starting process: cat CMakeLists.txt");
auto p = co_await co_await fs_pipe();
Pid pid = co_await co_await ProcessBuilder()
.path("cat")
.arg("CMakeLists.txt")
.open(1, p.writer())
.spawn();
auto rs = file_from_handle(p.reader());
String line;
while (line.clear(), co_await rs.getline(line, '\n')) {
co_await co_await stdio().putline("process output: " + line);
}
co_await rs.close();
co_await co_await stdio().putline("waiting process...");
auto res = co_await co_await wait_process(pid);
co_await co_await stdio().putline("process exited: " + to_string(res.status));
co_return {};
}
int main() {
co_main(amain());
return 0;
}