mirror of
https://github.com/arun11299/cpp-subprocess.git
synced 2025-08-05 04:46:21 -04:00

* 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
36 lines
803 B
C++
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;
|
|
}
|