I can send() but I have no way of closing the input channel #21

This commit is contained in:
Arun M 2018-12-31 17:41:24 +05:30
parent a90174cf5c
commit ced3d53e3a
3 changed files with 28 additions and 2 deletions

View File

@ -1012,6 +1012,11 @@ public:
FILE* output() { return stream_.output();} FILE* output() { return stream_.output();}
FILE* error() { return stream_.error(); } 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: private:
template <typename F, typename... Args> template <typename F, typename... Args>
void init_args(F&& farg, Args&&... args); void init_args(F&& farg, Args&&... args);

View File

@ -1 +1 @@
through stdin to stdoutthrough stdin to stdoutthrough stdin to stdoutthrough stdin to stdout through stdin to stdout

View File

@ -23,6 +23,24 @@ void test_cat_file_redirection()
std::cout << "END_TEST" << std::endl; std::cout << "END_TEST" << std::endl;
} }
void test_cat_send_terminate()
{
std::cout << "Test::test_cat_send_terminate" << std::endl;
std::vector<sp::Popen> 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() void test_buffer_growth()
{ {
auto obuf = sp::check_output({"cat", "../subprocess.hpp"}); auto obuf = sp::check_output({"cat", "../subprocess.hpp"});
@ -40,9 +58,12 @@ void test_buffer_growth_threaded_comm()
} }
int main() { int main() {
test_cat_pipe_redirection(); // test_cat_pipe_redirection();
test_cat_send_terminate();
/*
test_cat_file_redirection(); test_cat_file_redirection();
test_buffer_growth(); test_buffer_growth();
test_buffer_growth_threaded_comm(); test_buffer_growth_threaded_comm();
*/
return 0; return 0;
} }