mirror of
https://github.com/boostorg/process.git
synced 2026-01-20 04:42:24 +00:00
Compare commits
1 Commits
issue/491-
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1dcf21fbde |
@@ -25,7 +25,7 @@ include::../example/env.cpp[tag=current_env]
|
||||
The subprocess environment assignment follows the same constraints:
|
||||
|
||||
.example/env.cpp:34-42
|
||||
[source,cpp,ident=0]
|
||||
[source,cpp,indent=0]
|
||||
----
|
||||
include::../example/env.cpp[tag=subprocess_env]
|
||||
----
|
||||
@@ -36,7 +36,7 @@ The current environment can be obtained by calling `environment::current` which
|
||||
a forward range of `environment::key_value_pair_view`.
|
||||
|
||||
.example/env.cpp:48-54
|
||||
[source,cpp,ident=0]
|
||||
[source,cpp,indent=0]
|
||||
----
|
||||
include::../example/env.cpp[tag=vector_env]
|
||||
----
|
||||
@@ -44,7 +44,7 @@ include::../example/env.cpp[tag=vector_env]
|
||||
Alternatively you can use a map container for the environment.
|
||||
|
||||
.example/env.cpp:61-68
|
||||
[source,cpp,ident=0]
|
||||
[source,cpp,indent=0]
|
||||
----
|
||||
include::../example/env.cpp[tag=map_env]
|
||||
----
|
||||
|
||||
@@ -118,7 +118,7 @@ struct custom_initializer
|
||||
};
|
||||
----
|
||||
|
||||
NTOE: All the additional launchers for windows inherit `default_launcher`.
|
||||
NOTE: All the additional launchers for windows inherit `default_launcher`.
|
||||
|
||||
The call sequence is as follows:
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
== `bind_launcher.hpp`
|
||||
|
||||
The `bind_launcher` utlitities allow on the fly construction of a launcher with bound initializers.
|
||||
The `bind_launcher` utilities allow on the fly construction of a launcher with bound initializers.
|
||||
|
||||
[source,cpp]
|
||||
----
|
||||
|
||||
@@ -8,7 +8,7 @@ The `default_launcher` is the standard way of creating a process.
|
||||
asio::io_context ctx;
|
||||
process proc(ctx.get_executor(), "test", {});
|
||||
// equivalent to
|
||||
process prod = default_launcher()(ctx.get_executor(), "test", {});
|
||||
process proc = default_launcher()(ctx.get_executor(), "test", {});
|
||||
----
|
||||
|
||||
It has four overloads:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
== `popen.hpp`
|
||||
[#popen]
|
||||
|
||||
`popen` is a class that launches a process and connect stdin & stderr to pipes.
|
||||
`popen` is a class that launches a process and connect stdin & stdout to pipes.
|
||||
|
||||
[source,cpp]
|
||||
----
|
||||
|
||||
@@ -41,7 +41,7 @@ struct bind_fd
|
||||
process p{"test", {}, posix::bind_fd(42, 24)};
|
||||
|
||||
*/
|
||||
bind_fd(int target, int fd):
|
||||
bind_fd(int target, int fd);
|
||||
|
||||
// Inherit a null device as a set descriptor.
|
||||
/* This will a null device as 42 to the child process:
|
||||
|
||||
@@ -78,7 +78,7 @@ struct basic_process
|
||||
template<typename ExecutionContext, typename Args, typename ... Inits>
|
||||
explicit basic_process(
|
||||
ExecutionContext & context,
|
||||
const filesystem::path&>::type exe,
|
||||
const filesystem::path& exe,
|
||||
Args&& args, Inits&&... inits);
|
||||
|
||||
// Attach to an existing process
|
||||
@@ -142,7 +142,7 @@ struct basic_process
|
||||
native_handle_type native_handle() {return process_handle_.native_handle(); }
|
||||
|
||||
// Return the evaluated exit_code.
|
||||
int exit_code() cons;
|
||||
int exit_code() const;
|
||||
|
||||
// Get the id of the process;
|
||||
pid_type id() const;
|
||||
|
||||
@@ -97,7 +97,7 @@ inline void invoke_on_error(Launcher & /*launcher*/, const filesystem::path &/*e
|
||||
template<typename Launcher, typename Init>
|
||||
inline auto invoke_on_error(Launcher & launcher, const filesystem::path &executable, std::wstring &cmd_line,
|
||||
const error_code & ec, Init && init, derived && )
|
||||
-> decltype(init.on_error(launcher, executable, cmd_line, ec))
|
||||
-> decltype(init.on_error(launcher, executable, cmd_line, ec))
|
||||
{
|
||||
init.on_error(launcher, executable, cmd_line, ec);
|
||||
}
|
||||
@@ -109,7 +109,7 @@ inline std::false_type probe_on_error(
|
||||
|
||||
template<typename Launcher, typename Init>
|
||||
inline auto probe_on_error(Launcher & launcher, Init && init, derived && )
|
||||
-> std::is_same<void, decltype(init.on_error(launcher, std::declval<const filesystem::path &>(), std::declval<std::wstring &>(), std::declval<error_code&>()))>;
|
||||
-> std::is_same<error_code, decltype(init.on_error(launcher, std::declval<const filesystem::path &>(), std::declval<std::wstring &>(), std::declval<error_code&>()))>;
|
||||
|
||||
template<typename Launcher, typename Init>
|
||||
using has_on_error = decltype(probe_on_error(std::declval<Launcher&>(), std::declval<Init>(), derived{}));
|
||||
|
||||
@@ -933,56 +933,5 @@ BOOST_AUTO_TEST_CASE(print_args_combined)
|
||||
BOOST_CHECK_EQUAL(proc.exit_code(), 0);
|
||||
}
|
||||
|
||||
|
||||
struct my_handler
|
||||
{
|
||||
boost::process::filesystem::path pt;
|
||||
bpv::error_code ec;
|
||||
|
||||
template<typename Launcher, typename CmdLine>
|
||||
bpv::error_code on_setup(Launcher &launcher, const bpv::filesystem::path& executable,
|
||||
CmdLine (&/*cmd_line*/))
|
||||
{
|
||||
pt = executable;
|
||||
if (executable == "/send/more/cops")
|
||||
return asio::error::no_recovery;
|
||||
else
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename Launcher, typename CmdLine>
|
||||
void on_error(Launcher &launcher, const bpv::filesystem::path& executable,
|
||||
CmdLine (&/*cmd_line*/), const bpv::error_code & ec)
|
||||
{
|
||||
this->ec = ec;
|
||||
}
|
||||
|
||||
template<typename Launcher, typename CmdLine>
|
||||
void on_success(Launcher &launcher, const bpv::filesystem::path& executable,
|
||||
CmdLine (&/*cmd_line*/))
|
||||
{
|
||||
ec.clear();
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE(custom_handlers)
|
||||
{
|
||||
my_handler mh;
|
||||
|
||||
asio::io_context ctx;
|
||||
|
||||
BOOST_CHECK_THROW(bpv::process(ctx, "/send/more/cops", {}, mh), bpv::system_error);
|
||||
BOOST_CHECK_EQUAL(mh.ec, asio::error::no_recovery);
|
||||
|
||||
BOOST_CHECK_EQUAL(mh.pt, "/send/more/cops");
|
||||
|
||||
using boost::unit_test::framework::master_test_suite;
|
||||
const auto pth = bpv::filesystem::absolute(master_test_suite().argv[1]);
|
||||
|
||||
bpv::process proc(ctx, pth, {}, mh);
|
||||
|
||||
BOOST_CHECK_EQUAL(mh.pt, pth);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user