]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/process/example/io.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / process / example / io.cpp
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
6 //
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)
9
10 #include <boost/process.hpp>
11 #include <string>
12
13 namespace bp = boost::process;
14
15 int main()
16 {
17 //
18 bp::system(
19 "test.exe",
20 bp::std_out > stdout, //forward
21 bp::std_err.close(), //close
22 bp::std_in < bp::null //null in
23 );
24
25 boost::filesystem::path p = "input.txt";
26
27 bp::system(
28 "test.exe",
29 (bp::std_out & bp::std_err) > "output.txt", //redirect both to one file
30 bp::std_in < p //read input from file
31 );
32
33 {
34 bp::opstream p1;
35 bp::ipstream p2;
36 bp::system(
37 "test.exe",
38 bp::std_out > p2,
39 bp::std_in < p1
40 );
41 p1 << "my_text";
42 int i = 0;
43 p2 >> i;
44
45 }
46 {
47 boost::asio::io_context io_context;
48 bp::async_pipe p1(io_context);
49 bp::async_pipe p2(io_context);
50 bp::system(
51 "test.exe",
52 bp::std_out > p2,
53 bp::std_in < p1,
54 io_context,
55 bp::on_exit([&](int exit, const std::error_code& ec_in)
56 {
57 p1.async_close();
58 p2.async_close();
59 })
60 );
61 std::vector<char> in_buf;
62 std::string value = "my_string";
63 boost::asio::async_write(p1, boost::asio::buffer(value), []( const boost::system::error_code&, std::size_t){});
64 boost::asio::async_read (p2, boost::asio::buffer(in_buf), []( const boost::system::error_code&, std::size_t){});
65 }
66 {
67 boost::asio::io_context io_context;
68 std::vector<char> in_buf;
69 std::string value = "my_string";
70 bp::system(
71 "test.exe",
72 bp::std_out > bp::buffer(in_buf),
73 bp::std_in < bp::buffer(value)
74 );
75 }
76
77 {
78 boost::asio::io_context io_context;
79 std::future<std::vector<char>> in_buf;
80 std::future<void> write_fut;
81 std::string value = "my_string";
82 bp::system(
83 "test.exe",
84 bp::std_out > in_buf,
85 bp::std_in < bp::buffer(value) > write_fut
86 );
87
88 write_fut.get();
89 in_buf.get();
90 }
91 }