diff --git a/doc/tutorial.qbk b/doc/tutorial.qbk index a1cc6928..e53d9b97 100644 --- a/doc/tutorial.qbk +++ b/doc/tutorial.qbk @@ -77,6 +77,8 @@ system(cmd="grep -c false /etc/passwd"); //cmd style system(exe="grep", args={"-c", "false", "/etc/passwd"}); //exe-/args- ``` +[note If a '"' sign is used in the argument style, it will be passed as part of the argument. +If the same effect it wanted with the cmd syntax, it ought to be escaped, i.e. '\\\"'. ] [endsect] [section Synchronous I/O] diff --git a/example/Jamfile.jam b/example/Jamfile.jam index 69b75bc5..85df603a 100644 --- a/example/Jamfile.jam +++ b/example/Jamfile.jam @@ -9,7 +9,6 @@ project : requirements ../../.. - /boost//headers msvc:_SCL_SECURE_NO_WARNINGS windows:WIN32_LEAN_AND_MEAN ; @@ -19,7 +18,6 @@ import testing ; compile args.cpp ; compile async_io.cpp ; compile cleanup.cpp ; -compile cmd_line.cpp ; compile env.cpp ; compile error_handling.cpp ; compile execute.cpp ; diff --git a/example/args.cpp b/example/args.cpp index 1d83cbf4..5134a71d 100644 --- a/example/args.cpp +++ b/example/args.cpp @@ -12,16 +12,11 @@ #include using namespace boost::process; -using namespace boost::process::initializers; int main() { //[args - std::vector args; - args.push_back("test.exe"); - args.push_back("--foo"); - args.push_back("/bar"); - - execute(set_args(args)); + child c("test.exe", "--foo", "/bar"); //] + c.wait(); } diff --git a/example/async_io.cpp b/example/async_io.cpp index 52538869..7b5a0aaf 100644 --- a/example/async_io.cpp +++ b/example/async_io.cpp @@ -8,7 +8,6 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include -#include #include #include #include @@ -17,49 +16,22 @@ #endif using namespace boost::process; -using namespace boost::process::initializers; -using namespace boost::iostreams; - -boost::process::pipe create_async_pipe() -{ -#if defined(BOOST_WINDOWS_API) - std::string name = "\\\\.\\pipe\\boost_process_async_io"; - HANDLE handle1 = ::CreateNamedPipeA(name.c_str(), PIPE_ACCESS_INBOUND | - FILE_FLAG_OVERLAPPED, 0, 1, 8192, 8192, 0, NULL); - HANDLE handle2 = ::CreateFileA(name.c_str(), GENERIC_WRITE, 0, NULL, - OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); - return make_pipe(handle1, handle2); -#elif defined(BOOST_POSIX_API) - return create_pipe(); -#endif -} int main() { //[async_io - boost::process::pipe p = create_async_pipe(); + boost::asio::io_service ios; + boost::process::async_pipe p(ios); - file_descriptor_sink sink(p.sink, close_handle); - execute( - run_exe("test.exe"), - bind_stdout(sink) + child c( + "test.exe", + std_out > ios ); - file_descriptor_source source(p.source, close_handle); - -#if defined(BOOST_WINDOWS_API) - typedef boost::asio::windows::stream_handle pipe_end; -#elif defined(BOOST_POSIX_API) - typedef boost::asio::posix::stream_descriptor pipe_end; -#endif - - boost::asio::io_service io_service; - pipe_end pend(io_service, p.source); - boost::array buffer; - boost::asio::async_read(pend, boost::asio::buffer(buffer), + boost::asio::async_read(p, boost::asio::buffer(buffer), [](const boost::system::error_code&, std::size_t){}); - io_service.run(); + ios.run(); //] } diff --git a/example/cleanup.cpp b/example/cleanup.cpp index 9da5cf36..5904b03a 100644 --- a/example/cleanup.cpp +++ b/example/cleanup.cpp @@ -13,26 +13,24 @@ #endif using namespace boost::process; -using namespace boost::process::initializers; int main() { //[cleanup { - child c = execute("test.exe"); + child c("test.exe"); //wait for exit } //] //[cleanup_detach_short - execute("test.exe").detach(); + spawn("test.exe"); //] -//[cleanup_detach +//[cleanup_system { - child c = execute(run_exe("test.exe")); - c.detach() + system("test.exe"); } //] } diff --git a/example/env.cpp b/example/env.cpp index 54cdefae..24fce1d0 100644 --- a/example/env.cpp +++ b/example/env.cpp @@ -15,9 +15,9 @@ int main() { //[modifiy_env boost::process::environment my_env = boost::this_process::environment(); //empty env, that would fail. - execute("test.exe", my_env); + system("test.exe", my_env); //] //[inherit_env - execute("test.exe", env["PATH"]+="/tmp"); + system("test.exe", env["PATH"]+="/tmp"); //] } diff --git a/example/error_handling.cpp b/example/error_handling.cpp index d0b5a116..a293a2f5 100644 --- a/example/error_handling.cpp +++ b/example/error_handling.cpp @@ -11,16 +11,15 @@ #include using namespace boost::process; -using namespace boost::process::initializers; int main() { //[set_on_error std::error_code ec; - child c("test.exe", ec); + child c1("test.exe", ec); //] //[ignore_error - child c("test.exe", ignore_error); + child c2("test.exe", ignore_error); //] } diff --git a/example/execute.cpp b/example/execute.cpp index 713d6007..b18922f8 100644 --- a/example/execute.cpp +++ b/example/execute.cpp @@ -14,11 +14,11 @@ using namespace boost::process; int main() { //[execute - child c("test.exe"); + child c1("test.exe"); //] //[execute_path boost::filesystem::path exe = "../test.exe"; - child c(exe); + child c2(exe); //] } diff --git a/example/io.cpp b/example/io.cpp index a715ad37..6f4cbaf6 100644 --- a/example/io.cpp +++ b/example/io.cpp @@ -8,17 +8,15 @@ // 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( + system( "test.exe", std_out.close(), std_err.close(), @@ -26,7 +24,7 @@ int main() ); //] //[null - execute( + system( "test.exe", (std_out & std_err) > null, std_in < null @@ -34,34 +32,37 @@ int main() //] //[redirect boost::filesystem::path p = "input.txt"; - execute( + system( "test.exe", std_err > "log.txt", std_out > stderr, std_in < p ); //] + { //[pipe pipe p1; pipe p2; - execute( + system( "test.exe", std_out > p2, std_in < p1 ); auto text = "my_text"; - p1.write(test, 8); + p1.write(text, 8); boost::iostreams::stream istr(p2.source()); int i = 0; p2 >> i; //] + } + { //[async_pipe - io_service io_service; + boost::asio::io_service io_service; async_pipe p1(io_service); async_pipe p2(io_service); - execute( + system( "test.exe", std_out > p2, std_in < p1, @@ -74,26 +75,27 @@ int main() ); 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){}); + boost::asio::async_write(p1, boost::asio::buffer(value), []( const boost::system::error_code&, std::size_t){}); + boost::asio::async_read (p2, boost::asio::buffer(in_buf), []( const boost::system::error_code&, std::size_t){}); //] + }{ //[async_pipe_simple - io_service io_service; + boost::asio::io_service io_service; std::vector in_buf; std::string value = "my_string"; - execute( + system( "test.exe", std_out > buffer(in_buf), std_in < buffer(value) ); //] - + }{ //[async_pipe_future - io_service io_service; + boost::asio::io_service io_service; std::future> in_buf; std::future write_fut; std::string value = "my_string"; - execute( + system( "test.exe", std_out > in_buf, std_in < buffer(value) > write_fut @@ -102,4 +104,5 @@ int main() write_fut.get(); in_buf.get(); //] + } } diff --git a/example/posix.cpp b/example/posix.cpp index 21da84f4..2b901588 100644 --- a/example/posix.cpp +++ b/example/posix.cpp @@ -8,60 +8,40 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include -#include -#include +#include #include #include #include #include using namespace boost::process; -using namespace boost::process::initializers; -using namespace boost::iostreams; int main() { //[bind_fd - file_descriptor_sink sink("output.txt"); - execute( - run_exe("test"), - bind_fd(4, sink) - ); + + pipe p; + system("test", posix::fd.bind(4, p.native_sink()) ); //] //[close_fd - execute( - run_exe("test"), - close_fd(STDIN_FILENO) - ); + system("test", posix::fd.close(STDIN_FILENO)); //] //[close_fds - execute( - run_exe("test"), - close_fds(boost::assign::list_of(STDIN_FILENO)(4)) - ); -//] - -//[close_fds_if - execute( - run_exe("test"), - close_fds_if([](int fd){ return fd == STDIN_FILENO; }) - ); + system("test", posix::fd.close({STDIN_FILENO, STDOUT_FILENO})); //] //[fork_execve const char *env[2] = { 0 }; env[0] = "LANG=de"; - execute( - run_exe("test"), - on_fork_setup([env](executor &e) - { e.env = const_cast(env); }), - on_fork_error([](executor&) + system("test", + on_setup([env](auto &e) { e.env = const_cast(env); }), + posix::on_fork_error([](auto&) { std::cerr << errno << std::endl; }), - on_exec_setup([](executor&) - { chroot("/new/root/directory/"); }), - on_exec_error([](executor&) + posix::on_exec_setup([](auto&) + { ::chroot("/new/root/directory/"); }), + posix::on_exec_error([](auto&) { std::ofstream ofs("log.txt"); if (ofs) ofs << errno; }) ); //] diff --git a/example/streams.cpp b/example/streams.cpp index 33198200..30112b7f 100644 --- a/example/streams.cpp +++ b/example/streams.cpp @@ -9,28 +9,20 @@ #include #include -#include using namespace boost::process; -using namespace boost::process::initializers; using namespace boost::iostreams; int main() { //[stdout - file_descriptor_sink sink("stdout.txt"); - execute( - run_exe("test.exe"), - bind_stdout(sink) - ); + system("test.exe", std_out > "log.txt"); //] //[close_in_err - execute( - run_exe("test.exe"), - bind_stdout(sink), - close_stdin(), - close_stderr() - ); + system("test.exe", + std_out > null, + std_in < null, + std_err.close()); //] } diff --git a/example/sync_io.cpp b/example/sync_io.cpp index cc36c40d..85c35ed4 100644 --- a/example/sync_io.cpp +++ b/example/sync_io.cpp @@ -8,28 +8,24 @@ // 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::process::initializers; -using namespace boost::iostreams; int main() { //[sync_io - boost::process::pipe p = create_pipe(); + boost::process::ipstream p; - file_descriptor_sink sink(p.sink, close_handle); - execute( - run_exe("test.exe"), - bind_stdout(sink) + child c( + "test.exe", + std_out > p ); - file_descriptor_source source(p.source, close_handle); - stream is(source); + std::string s; - std::getline(is, s); + std::getline(p, s); + + c.wait(); //] } diff --git a/example/terminate.cpp b/example/terminate.cpp index eddb0ddf..aab828f1 100644 --- a/example/terminate.cpp +++ b/example/terminate.cpp @@ -10,12 +10,11 @@ #include using namespace boost::process; -using namespace boost::process::initializers; int main() { //[c_terminate - child c = execute("test.exe"); + child c("test.exe"); c.terminate(); //] } diff --git a/example/wait.cpp b/example/wait.cpp index 48af5a42..73fca1b1 100644 --- a/example/wait.cpp +++ b/example/wait.cpp @@ -17,14 +17,14 @@ #endif using namespace boost::process; -using namespace boost::process::initializers; int main() { { //[sync - child c = execute(run_exe("test.exe")); - auto exit_code = wait_for_exit(c); + child c("test.exe"); + c.wait(); + auto exit_code = c.exit_code(); //] } @@ -32,11 +32,10 @@ int main() //[async boost::asio::io_service io_service; - child c; - c = execute( - run_exe("test.exe"), + child c( + "test.exe", io_service, - on_exit([&](int exit, const std::error_code& ec_in){c.set_exit(exit);}) + on_exit([&](int exit, const std::error_code& ec_in){}) ); io_service.run(); diff --git a/example/windows.cpp b/example/windows.cpp index e2b2955b..0b2ae4e7 100644 --- a/example/windows.cpp +++ b/example/windows.cpp @@ -8,28 +8,26 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include +#include #include -#include + +#include using namespace boost::process; -using namespace boost::process::initializers; int main() { //[show_window - execute( - run_exe("test.exe"), - show_window(SW_HIDE) - ); + system("test.exe", + windows::show); //] //[create_process - execute( - run_exe("test.exe"), - on_CreateProcess_setup([](executor &e) + system("test.exe", + on_setup([](auto &e) { e.startup_info.dwFlags = STARTF_RUNFULLSCREEN; }), - on_CreateProcess_error([](executor&) - { std::cerr << GetLastError() << std::endl; }) + on_error([](auto&, const std::error_code & ec) + { std::cerr << ec.message() << std::endl; }) ); //] } diff --git a/example/windows_unicode.cpp b/example/windows_unicode.cpp deleted file mode 100644 index 1585cb28..00000000 --- a/example/windows_unicode.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// 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) - -//[unicode -#define UNICODE -#include -#include - -using namespace boost::process; -using namespace boost::process::initializers; - -int main() -{ - boost::filesystem::path p = L"C:\\"; - execute( - run_exe(L"test.exe"), - set_cmd_line(L"test --help"), - start_in_dir(p) - ); -} -//] diff --git a/example/work_dir.cpp b/example/work_dir.cpp index 679181f6..ea54d37a 100644 --- a/example/work_dir.cpp +++ b/example/work_dir.cpp @@ -11,12 +11,11 @@ #include using namespace boost::process; -using namespace boost::process::initializers; int main() { //[work_dir - execute( + system( "test.exe", start_dir="../foo" ); @@ -24,7 +23,7 @@ int main() //[work_dir_abs boost::filesystem::path exe = "test.exe"; - execute( + system( boost::filesystem::absolute(exe), start_dir="../foo" ); diff --git a/include/boost/process/env.hpp b/include/boost/process/env.hpp index cb98354b..a48336b3 100644 --- a/include/boost/process/env.hpp +++ b/include/boost/process/env.hpp @@ -106,7 +106,7 @@ struct env_ { return {key}; } - env_proxy operator[](const std::string & key) + env_proxy operator[](const std::string & key) const { return {key}; } diff --git a/include/boost/process/start_dir.hpp b/include/boost/process/start_dir.hpp index 18595d05..4ff84982 100644 --- a/include/boost/process/start_dir.hpp +++ b/include/boost/process/start_dir.hpp @@ -36,10 +36,12 @@ struct start_dir_ api::start_dir_init operator()(const std::string & st) const {return api::start_dir_init(st); } api::start_dir_init operator()(std::string && s) const {return api::start_dir_init(std::move(s)); } + api::start_dir_init operator()(const char* s) const {return api::start_dir_init(s); } api::start_dir_init operator()(const boost::filesystem::path & st) const {return api::start_dir_init(st.string()); } api::start_dir_init operator=(const std::string & st) const {return api::start_dir_init(st); } api::start_dir_init operator=(std::string && s) const {return api::start_dir_init(std::move(s)); } + api::start_dir_init operator=(const char* s) const {return api::start_dir_init(s); } api::start_dir_init operator=(const boost::filesystem::path & st) const {return api::start_dir_init(st.string()); } }; diff --git a/test/Jamfile.jam b/test/Jamfile.jam index 7cf9fbe4..9e06980c 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -8,8 +8,6 @@ # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) project : requirements - # /boost//headers - # /boost//system msvc:_SCL_5SECURE_NO_WARNINGS windows:WIN32_LEAN_AND_MEAN linux:-lpthread