diff --git a/subprocess.hpp b/subprocess.hpp index ebf1484..8f54478 100755 --- a/subprocess.hpp +++ b/subprocess.hpp @@ -1012,6 +1012,11 @@ public: FILE* output() { return stream_.output();} FILE* error() { return stream_.error(); } + /// Stream close APIs + void close_input() { stream_.input_.reset(); } + void close_output() { stream_.output_.reset(); } + void close_error() { stream_.error_.reset(); } + private: template void init_args(F&& farg, Args&&... args); diff --git a/test/cat_fredirect.txt b/test/cat_fredirect.txt index 15e3834..29c84d2 100644 --- a/test/cat_fredirect.txt +++ b/test/cat_fredirect.txt @@ -1 +1 @@ -through stdin to stdoutthrough stdin to stdoutthrough stdin to stdoutthrough stdin to stdout \ No newline at end of file +through stdin to stdout \ No newline at end of file diff --git a/test/test_cat.cc b/test/test_cat.cc index c103364..76ca6a4 100755 --- a/test/test_cat.cc +++ b/test/test_cat.cc @@ -23,6 +23,24 @@ void test_cat_file_redirection() std::cout << "END_TEST" << std::endl; } +void test_cat_send_terminate() +{ + std::cout << "Test::test_cat_send_terminate" << std::endl; + std::vector pops; + + for (int i=0; i < 5; i++) { + pops.emplace_back(sp::Popen({"cat", "-"}, sp::input{sp::PIPE})); + pops[i].send("3 5\n", 5); + pops[i].close_input(); + } + + for (int i=0; i < 5; i++) { + pops[i].wait(); + } + + std::cout << "END_TEST" << std::endl; +} + void test_buffer_growth() { auto obuf = sp::check_output({"cat", "../subprocess.hpp"}); @@ -40,9 +58,12 @@ void test_buffer_growth_threaded_comm() } int main() { - test_cat_pipe_redirection(); + // test_cat_pipe_redirection(); + test_cat_send_terminate(); + /* test_cat_file_redirection(); test_buffer_growth(); test_buffer_growth_threaded_comm(); + */ return 0; }