Skip to content

Commit

Permalink
close #296.
Browse files Browse the repository at this point in the history
  • Loading branch information
klemens-morgenstern committed Feb 20, 2023
1 parent f703845 commit 8d93576
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 4 additions & 2 deletions include/boost/process/detail/posix/basic_cmd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,15 @@ struct exe_cmd_init<char> : boost::process::detail::api::handler_base_ext

std::vector<char*> exe_cmd_init<char>::make_cmd()
{
// any string must be writable.
static char empty_string[1] = "";
std::vector<char*> vec;
if (!exe.empty())
vec.push_back(&exe.front());
vec.push_back(exe.empty() ? empty_string : &exe.front());

if (!args.empty()) {
for (auto & v : args)
vec.push_back(&v.front());
vec.push_back(v.empty() ? empty_string : &v.front());
}

vec.push_back(nullptr);
Expand Down
21 changes: 21 additions & 0 deletions test/cmd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,24 @@ BOOST_AUTO_TEST_CASE(implicit)
BOOST_TEST_MESSAGE(ec.message());
BOOST_CHECK_EQUAL(ret, 21);
}

BOOST_AUTO_TEST_CASE(empty_cmd)
{
using boost::unit_test::framework::master_test_suite;

std::error_code ec;

fs::path pth = master_test_suite().argv[1];
auto env = boost::this_process::environment();

auto itr = std::find_if(env.begin(), env.end(),
[](const bp::native_environment::entry_type & e){return boost::to_upper_copy(e.get_name()) == "PATH";});

BOOST_REQUIRE(itr != env.end());

(*itr) += fs::canonical(fs::absolute(pth.parent_path())).string();
BOOST_REQUIRE(itr != env.end());

bp::system("sparring_partner \"\" ", ec);
}

0 comments on commit 8d93576

Please sign in to comment.