From dc19c718f0b51eaeb07edf282af1377d0bc3294d Mon Sep 17 00:00:00 2001 From: klemens-morgenstern Date: Mon, 13 Jun 2016 18:39:59 +0200 Subject: [PATCH] shell fix for windows --- .../process/detail/windows/basic_cmd.hpp | 2 +- test/shell.cpp | 44 ++++++++++++++----- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/include/boost/process/detail/windows/basic_cmd.hpp b/include/boost/process/detail/windows/basic_cmd.hpp index ea7f5997..45cc9ff9 100644 --- a/include/boost/process/detail/windows/basic_cmd.hpp +++ b/include/boost/process/detail/windows/basic_cmd.hpp @@ -85,7 +85,7 @@ struct exe_cmd_init : handler_base_ext } static exe_cmd_init exe_args_shell(std::string&& exe, std::vector && args) { - std::vector args_ = {"/c"}; + std::vector args_ = {"/c", std::move(exe)}; args_.insert(args_.end(), std::make_move_iterator(args.begin()), std::make_move_iterator(args.end())); std::string sh = shell().string(); return exe_cmd_init(std::move(sh), std::move(args_)); diff --git a/test/shell.cpp b/test/shell.cpp index cc7b4e49..97486d10 100644 --- a/test/shell.cpp +++ b/test/shell.cpp @@ -7,33 +7,57 @@ // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#include +#define BOOST_TEST_MAIN +#define BOOST_TEST_IGNORE_SIGCHLD +#include #include #include +#include +#include +#include #include #include #include namespace bp = boost::process; -int main(int argc, char* argv[]) +BOOST_AUTO_TEST_CASE(shell_simple, *boost::unit_test::timeout(5)) { - std::error_code ec; - BOOST_TEST(!ec); + using boost::unit_test::framework::master_test_suite; - bp::child c(argv[1], bp::shell, ec); - BOOST_TEST(!ec); + std::error_code ec; + BOOST_CHECK(!ec); + + bp::ipstream p; + + bp::child c(master_test_suite().argv[1], + bp::shell, + bp::args+={"test", "--echo-stdout", "hello"}, + ec, + bp::std_out > p); + BOOST_CHECK(!ec); if (ec) std::cerr << ec.message() << std::endl; + std::string s; + + BOOST_TEST_CHECKPOINT("Starting read"); + p >> s; + BOOST_TEST_CHECKPOINT("Finished read"); + + BOOST_CHECK_EQUAL(s, "hello"); +} + +BOOST_AUTO_TEST_CASE(shell_error, *boost::unit_test::timeout(5)) +{ + std::error_code ec; + auto c2 = bp::child("doesnt-exist", bp::shell, ec); - BOOST_TEST(!ec); + BOOST_CHECK(!ec); c2.wait(); - BOOST_TEST(c2.exit_code() != 0); - - return boost::report_errors(); + BOOST_CHECK(c2.exit_code() != 0); }