cpp-subprocess/test/test_ret_code.cc
xoviat 9c624ce4e3 Enable basic windows support (#33)
* windows: fix implementation error
- repair configure_pipe
- allow vector initialization
- add draft destructor
- close pipes correctly

* windows: add some test compatibility

* windows: update readme

* windows: add vector args to check_output
2020-01-18 20:01:03 +05:30

36 lines
803 B
C++

#include <iostream>
#include "../subprocess.hpp"
namespace sp = subprocess;
void test_ret_code()
{
std::cout << "Test::test_poll_ret_code" << std::endl;
auto p = sp::Popen({"/usr/bin/false"});
while (p.poll() == -1) {
#ifndef _MSC_VER
usleep(1000 * 100);
#endif
}
assert (p.retcode() == 1);
}
void test_ret_code_comm()
{
using namespace sp;
auto cat = Popen({"cat", "../subprocess.hpp"}, output{PIPE});
auto grep = Popen({"grep", "template"}, input{cat.output()}, output{PIPE});
auto cut = Popen({"cut", "-d,", "-f", "1"}, input{grep.output()}, output{PIPE});
auto res = cut.communicate().first;
std::cout << res.buf.data() << std::endl;
std::cout << "retcode: " << cut.retcode() << std::endl;
}
int main() {
// test_ret_code();
test_ret_code_comm();
return 0;
}