diff --git a/subprocess.hpp b/subprocess.hpp index 7b24564..1e68096 100755 --- a/subprocess.hpp +++ b/subprocess.hpp @@ -1245,11 +1245,12 @@ namespace detail { } void ArgumentDeducer::set_option(error&& err) { - if (err.deferred_ && popen_->stream_.write_to_parent_) { - popen_->stream_.err_write_ = popen_->stream_.write_to_parent_; - return; - } else { - throw "Set output before redirecting error to output"; + if (err.deferred_) { + if (popen_->stream_.write_to_parent_) { + popen_->stream_.err_write_ = popen_->stream_.write_to_parent_; + } else { + throw std::runtime_error("Set output before redirecting error to output"); + } } if (err.wr_ch_ != -1) popen_->stream_.err_write_ = err.wr_ch_; if (err.rd_ch_ != -1) popen_->stream_.err_read_ = err.rd_ch_; @@ -1466,26 +1467,23 @@ namespace detail { { OutBuffer obuf; ErrBuffer ebuf; - std::future out_fut, err_fut; if (stream_->output()) { obuf.add_cap(out_buf_cap_); out_fut = std::async(std::launch::async, - util::read_atmost_n, - fileno(stream_->output()), - obuf.buf.data(), - obuf.buf.size()); + [&obuf, this] { + return util::read_all(fileno(this->stream_->output()), obuf.buf); + }); } if (stream_->error()) { ebuf.add_cap(err_buf_cap_); err_fut = std::async(std::launch::async, - util::read_atmost_n, - fileno(stream_->error()), - ebuf.buf.data(), - ebuf.buf.size()); + [&ebuf, this] { + return util::read_all(fileno(this->stream_->error()), ebuf.buf); + }); } if (stream_->input()) { if (msg) { @@ -1527,7 +1525,7 @@ namespace detail { static_assert(!detail::has_type>::value, "output not allowed in args"); auto p = Popen(std::forward(farg), std::forward(args)..., output{PIPE}); - auto res = p.communicate(nullptr, 0); + auto res = p.communicate(); auto retcode = p.poll(); if (retcode > 0) { throw CalledProcessError("Command failed : Non zero retcode"); diff --git a/test/test_cat b/test/test_cat deleted file mode 100755 index d874247..0000000 Binary files a/test/test_cat and /dev/null differ diff --git a/test/test_cat.cc b/test/test_cat.cc index db75e29..8c9ac93 100755 --- a/test/test_cat.cc +++ b/test/test_cat.cc @@ -30,9 +30,19 @@ void test_buffer_growth() assert (obuf.length > sp::DEFAULT_BUF_CAP_BYTES); } +void test_buffer_growth_threaded_comm() +{ + std::cout << "Test::test_buffer_growth_threaded_comm" << std::endl; + auto buf = sp::check_output("cat ../subprocess.hpp", sp::error{sp::PIPE}); + std::cout << buf.length << std::endl; + assert (buf.length > sp::DEFAULT_BUF_CAP_BYTES); + std::cout << "END_TEST" << std::endl; +} + int main() { test_cat_pipe_redirection(); test_cat_file_redirection(); test_buffer_growth(); + test_buffer_growth_threaded_comm(); return 0; } diff --git a/test/test_env b/test/test_env deleted file mode 100755 index 8634626..0000000 Binary files a/test/test_env and /dev/null differ diff --git a/test/test_split b/test/test_split deleted file mode 100755 index 5736605..0000000 Binary files a/test/test_split and /dev/null differ