diff --git a/example/cleanup.cpp b/example/cleanup.cpp index 6d40eee0..9da5cf36 100644 --- a/example/cleanup.cpp +++ b/example/cleanup.cpp @@ -18,20 +18,21 @@ using namespace boost::process::initializers; int main() { //[cleanup - child c = execute(run_exe("test.exe")); - wait_for_exit(c); + { + child c = execute("test.exe"); + //wait for exit + } //] -//[cleanup_posix -#if defined(BOOST_POSIX_API) - signal(SIGCHLD, SIG_IGN); -#endif - execute(run_exe("test.exe")); +//[cleanup_detach_short + + execute("test.exe").detach(); //] -//[cleanup_windows +//[cleanup_detach { child c = execute(run_exe("test.exe")); + c.detach() } //] } diff --git a/example/env.cpp b/example/env.cpp index d890af98..54cdefae 100644 --- a/example/env.cpp +++ b/example/env.cpp @@ -10,14 +10,14 @@ #include using namespace boost::process; -using namespace boost::process::initializers; int main() { +//[modifiy_env + boost::process::environment my_env = boost::this_process::environment(); //empty env, that would fail. + execute("test.exe", my_env); +//] //[inherit_env - execute( - run_exe("test.exe"), - inherit_env() - ); + execute("test.exe", env["PATH"]+="/tmp"); //] } diff --git a/example/error_handling.cpp b/example/error_handling.cpp index 4f7a261c..f63c333c 100644 --- a/example/error_handling.cpp +++ b/example/error_handling.cpp @@ -8,7 +8,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include -#include +#include using namespace boost::process; using namespace boost::process::initializers; @@ -16,17 +16,11 @@ using namespace boost::process::initializers; int main() { //[set_on_error - boost::system::error_code ec; - execute( - run_exe("test.exe"), - set_on_error(ec) - ); + std::error_code ec; + execute("test.exe", ec); //] -//[throw_on_error - execute( - run_exe("test.exe"), - throw_on_error() - ); +//[ignore_error + execute("test.exe", ignore_error); //] } diff --git a/example/execute.cpp b/example/execute.cpp index e8bd5947..954c6894 100644 --- a/example/execute.cpp +++ b/example/execute.cpp @@ -15,11 +15,11 @@ using namespace boost::process::initializers; int main() { //[execute - execute(run_exe("test.exe")); + execute("test.exe"); //] //[execute_path boost::filesystem::path exe = "../test.exe"; - execute(run_exe(exe)); + execute(exe); //] } diff --git a/example/intro.cpp b/example/intro.cpp index ce9b1a41..49b558ea 100644 --- a/example/intro.cpp +++ b/example/intro.cpp @@ -11,10 +11,9 @@ #include using namespace boost::process; -using namespace boost::process::initializers; int main() { - execute(run_exe("test.exe")); + execute("test.exe"); } //] diff --git a/example/io.cpp b/example/io.cpp new file mode 100644 index 00000000..a715ad37 --- /dev/null +++ b/example/io.cpp @@ -0,0 +1,105 @@ +// Copyright (c) 2006, 2007 Julio M. Merino Vidal +// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling +// Copyright (c) 2009 Boris Schaeling +// Copyright (c) 2010 Felipe Tanus, Boris Schaeling +// Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling +// +// 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 +#include +#include +#include + +using namespace boost::process; +using namespace boost::iostreams; + +int main() +{ +//[close + execute( + "test.exe", + std_out.close(), + std_err.close(), + std_in.close() + ); +//] +//[null + execute( + "test.exe", + (std_out & std_err) > null, + std_in < null + ); +//] +//[redirect + boost::filesystem::path p = "input.txt"; + execute( + "test.exe", + std_err > "log.txt", + std_out > stderr, + std_in < p + ); +//] +//[pipe + pipe p1; + pipe p2; + execute( + "test.exe", + std_out > p2, + std_in < p1 + ); + auto text = "my_text"; + p1.write(test, 8); + boost::iostreams::stream istr(p2.source()); + + int i = 0; + p2 >> i; + +//] +//[async_pipe + io_service io_service; + async_pipe p1(io_service); + async_pipe p2(io_service); + execute( + "test.exe", + std_out > p2, + std_in < p1, + io_service, + on_exit([&](int exit, const std::error_code& ec_in) + { + p1.async_close(); + p2.async_close(); + }) + ); + std::vector in_buf; + std::string value = "my_string"; + boost::asio::async_write(p1, boost::buffer(value), []( const boost::system::error_code&, std::size_t){}); + boost::asio::async_read (p2, boost::buffer(in_buf), []( const boost::system::error_code&, std::size_t){}); +//] +//[async_pipe_simple + io_service io_service; + std::vector in_buf; + std::string value = "my_string"; + execute( + "test.exe", + std_out > buffer(in_buf), + std_in < buffer(value) + ); +//] + +//[async_pipe_future + io_service io_service; + std::future> in_buf; + std::future write_fut; + std::string value = "my_string"; + execute( + "test.exe", + std_out > in_buf, + std_in < buffer(value) > write_fut + ); + + write_fut.get(); + in_buf.get(); +//] +} diff --git a/example/terminate.cpp b/example/terminate.cpp index 7518e5cb..eddb0ddf 100644 --- a/example/terminate.cpp +++ b/example/terminate.cpp @@ -14,8 +14,8 @@ using namespace boost::process::initializers; int main() { -//[terminate - child c = execute(run_exe("test.exe")); - terminate(c); +//[c_terminate + child c = execute("test.exe"); + c.terminate(); //] } diff --git a/example/wait.cpp b/example/wait.cpp index c47edac0..48af5a42 100644 --- a/example/wait.cpp +++ b/example/wait.cpp @@ -32,29 +32,12 @@ int main() //[async boost::asio::io_service io_service; -#if defined(BOOST_POSIX_API) - int status; - boost::asio::signal_set set(io_service, SIGCHLD); - set.async_wait( - [&status](const boost::system::error_code&, int) { ::wait(&status); } + child c; + c = execute( + run_exe("test.exe"), + io_service, + on_exit([&](int exit, const std::error_code& ec_in){c.set_exit(exit);}) ); -#endif - - child c = execute( - run_exe("test.exe") -#if defined(BOOST_POSIX_API) - , notify_io_service(io_service) -#endif - ); - -#if defined(BOOST_WINDOWS_API) - DWORD exit_code; - boost::asio::windows::object_handle handle(io_service, c.process_handle()); - handle.async_wait( - [&handle, &exit_code](const boost::system::error_code&) - { ::GetExitCodeProcess(handle.native(), &exit_code); } - ); -#endif io_service.run(); //] diff --git a/example/work_dir.cpp b/example/work_dir.cpp index cb17fd8d..679181f6 100644 --- a/example/work_dir.cpp +++ b/example/work_dir.cpp @@ -17,16 +17,16 @@ int main() { //[work_dir execute( - run_exe("test.exe"), - start_in_dir("../foo") + "test.exe", + start_dir="../foo" ); //] //[work_dir_abs boost::filesystem::path exe = "test.exe"; execute( - run_exe(boost::filesystem::absolute(exe)), - start_in_dir("../foo") + boost::filesystem::absolute(exe), + start_dir="../foo" ); //] }