1 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
2 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
3 // Copyright (c) 2009 Boris Schaeling
4 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
5 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 #include <boost/process.hpp>
11 #include <boost/process/posix.hpp>
12 #include <boost/process/extend.hpp>
18 namespace bp = boost::process;
23 //duplicate our pipe descriptor into literal position 4
25 bp::system("test", bp::posix::fd.bind(4, p.native_sink()));
28 //close file-descriptor from explicit integral value
29 bp::system("test", bp::posix::fd.close(STDIN_FILENO));
31 //close file-descriptors from explicit integral values
32 bp::system("test", bp::posix::fd.close({STDIN_FILENO, STDOUT_FILENO}));
35 const char *env[2] = { 0 };
38 bp::extend::on_setup([env](auto &e) { e.env = const_cast<char**>(env); }),
39 bp::extend::on_fork_error([](auto&, const std::error_code & ec)
40 { std::cerr << errno << std::endl; }),
41 bp::extend::on_exec_setup([](auto&)
42 { ::chroot("/new/root/directory/"); }),
43 bp::extend::on_exec_error([](auto&, const std::error_code & ec)
44 { std::ofstream ofs("log.txt"); if (ofs) ofs << errno; })