mirror of
https://github.com/arun11299/cpp-subprocess.git
synced 2025-08-04 20:36:20 -04:00
Fixed 2 issues:
1. When more than 2 streams are piped, we use threads to read/write data parallely. In this scenariod read_atmost_n API was being used instead of read_all. 2. Another issue with check_output argument validation fixed.
This commit is contained in:
parent
a67cb2a439
commit
a23c1033df
@ -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<int> 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<output, detail::param_pack<Args...>>::value, "output not allowed in args");
|
||||
auto p = Popen(std::forward<F>(farg), std::forward<Args>(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");
|
||||
|
BIN
test/test_cat
BIN
test/test_cat
Binary file not shown.
@ -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;
|
||||
}
|
||||
|
BIN
test/test_env
BIN
test/test_env
Binary file not shown.
BIN
test/test_split
BIN
test/test_split
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user