summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/process/example
diff options
context:
space:
mode:
Diffstat (limited to 'src/boost/libs/process/example')
-rw-r--r--src/boost/libs/process/example/Jamfile.jam28
-rw-r--r--src/boost/libs/process/example/args.cpp29
-rw-r--r--src/boost/libs/process/example/async_io.cpp30
-rw-r--r--src/boost/libs/process/example/env.cpp24
-rw-r--r--src/boost/libs/process/example/error_handling.cpp24
-rw-r--r--src/boost/libs/process/example/intro.cpp27
-rw-r--r--src/boost/libs/process/example/io.cpp91
-rw-r--r--src/boost/libs/process/example/posix.cpp47
-rw-r--r--src/boost/libs/process/example/start_dir.cpp27
-rw-r--r--src/boost/libs/process/example/sync_io.cpp28
-rw-r--r--src/boost/libs/process/example/terminate.cpp18
-rw-r--r--src/boost/libs/process/example/wait.cpp34
-rw-r--r--src/boost/libs/process/example/windows.cpp30
13 files changed, 437 insertions, 0 deletions
diff --git a/src/boost/libs/process/example/Jamfile.jam b/src/boost/libs/process/example/Jamfile.jam
new file mode 100644
index 000000000..4a9aa06f8
--- /dev/null
+++ b/src/boost/libs/process/example/Jamfile.jam
@@ -0,0 +1,28 @@
+# 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)
+
+project : requirements
+ <include>../../..
+ <toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS
+ <target-os>windows:<define>WIN32_LEAN_AND_MEAN
+;
+
+import testing ;
+
+compile args.cpp ;
+compile async_io.cpp ;
+compile env.cpp ;
+compile error_handling.cpp ;
+compile io.cpp ;
+compile posix.cpp : <build>no <target-os>linux:<build>yes ;
+compile start_dir.cpp ;
+compile sync_io.cpp ;
+compile terminate.cpp ;
+compile wait.cpp ;
+compile windows.cpp : <build>no <target-os>windows:<build>yes ;
diff --git a/src/boost/libs/process/example/args.cpp b/src/boost/libs/process/example/args.cpp
new file mode 100644
index 000000000..efad00d10
--- /dev/null
+++ b/src/boost/libs/process/example/args.cpp
@@ -0,0 +1,29 @@
+// 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 <boost/process.hpp>
+#include <vector>
+#include <string>
+
+namespace bp = boost::process;
+
+int main()
+{
+ bp::child c("test.exe", "--foo", "/bar");
+
+ //or explicit
+
+ bp::child c2(
+ bp::exe="test.exe",
+ bp::args={"--foo", "/bar"}
+ );
+
+ c.wait();
+ c2.wait();
+}
diff --git a/src/boost/libs/process/example/async_io.cpp b/src/boost/libs/process/example/async_io.cpp
new file mode 100644
index 000000000..6ac18de7c
--- /dev/null
+++ b/src/boost/libs/process/example/async_io.cpp
@@ -0,0 +1,30 @@
+// 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 <boost/process.hpp>
+#include <boost/asio.hpp>
+#include <boost/array.hpp>
+#include <string>
+
+namespace bp = boost::process;
+
+int main()
+{
+ boost::asio::io_context ios;
+ boost::asio::streambuf buffer;
+
+
+ bp::child c(
+ "test.exe",
+ bp::std_out > buffer,
+ ios
+ );
+
+ ios.run();
+}
diff --git a/src/boost/libs/process/example/env.cpp b/src/boost/libs/process/example/env.cpp
new file mode 100644
index 000000000..cb9a609b6
--- /dev/null
+++ b/src/boost/libs/process/example/env.cpp
@@ -0,0 +1,24 @@
+// 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 <boost/process.hpp>
+
+namespace bp = boost::process;
+
+int main()
+{
+ bp::environment my_env = boost::this_process::environment();
+
+ my_env["PATH"] += "/foo";
+ bp::system("test.exe", my_env);
+
+
+
+ bp::system("test.exe", bp::env["PATH"]+="/bar");
+}
diff --git a/src/boost/libs/process/example/error_handling.cpp b/src/boost/libs/process/example/error_handling.cpp
new file mode 100644
index 000000000..1a0dad002
--- /dev/null
+++ b/src/boost/libs/process/example/error_handling.cpp
@@ -0,0 +1,24 @@
+// 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 <boost/process.hpp>
+#include <system_error>
+
+namespace bp = boost::process;
+
+int main()
+{
+
+ std::error_code ec;
+ bp::child c1("test.exe", ec);
+
+
+ bp::child c2("test.exe", bp::ignore_error);
+
+}
diff --git a/src/boost/libs/process/example/intro.cpp b/src/boost/libs/process/example/intro.cpp
new file mode 100644
index 000000000..4e1127cab
--- /dev/null
+++ b/src/boost/libs/process/example/intro.cpp
@@ -0,0 +1,27 @@
+// 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)
+
+//[intro
+#include <boost/process.hpp>
+
+using namespace boost::process;
+
+int main()
+{
+ ipstream pipe_stream;
+ child c("gcc --version", std_out > pipe_stream);
+
+ std::string line;
+
+ while (pipe_stream && std::getline(pipe_stream, line) && !line.empty())
+ std::cerr << line << std::endl;
+
+ c.wait();
+}
+//]
diff --git a/src/boost/libs/process/example/io.cpp b/src/boost/libs/process/example/io.cpp
new file mode 100644
index 000000000..1b1e8eb77
--- /dev/null
+++ b/src/boost/libs/process/example/io.cpp
@@ -0,0 +1,91 @@
+// 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 <boost/process.hpp>
+#include <string>
+
+namespace bp = boost::process;
+
+int main()
+{
+ //
+ bp::system(
+ "test.exe",
+ bp::std_out > stdout, //forward
+ bp::std_err.close(), //close
+ bp::std_in < bp::null //null in
+ );
+
+ boost::filesystem::path p = "input.txt";
+
+ bp::system(
+ "test.exe",
+ (bp::std_out & bp::std_err) > "output.txt", //redirect both to one file
+ bp::std_in < p //read input from file
+ );
+
+ {
+ bp::opstream p1;
+ bp::ipstream p2;
+ bp::system(
+ "test.exe",
+ bp::std_out > p2,
+ bp::std_in < p1
+ );
+ p1 << "my_text";
+ int i = 0;
+ p2 >> i;
+
+ }
+ {
+ boost::asio::io_context io_context;
+ bp::async_pipe p1(io_context);
+ bp::async_pipe p2(io_context);
+ bp::system(
+ "test.exe",
+ bp::std_out > p2,
+ bp::std_in < p1,
+ io_context,
+ bp::on_exit([&](int exit, const std::error_code& ec_in)
+ {
+ p1.async_close();
+ p2.async_close();
+ })
+ );
+ std::vector<char> in_buf;
+ std::string value = "my_string";
+ 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){});
+ }
+ {
+ boost::asio::io_context io_context;
+ std::vector<char> in_buf;
+ std::string value = "my_string";
+ bp::system(
+ "test.exe",
+ bp::std_out > bp::buffer(in_buf),
+ bp::std_in < bp::buffer(value)
+ );
+ }
+
+ {
+ boost::asio::io_context io_context;
+ std::future<std::vector<char>> in_buf;
+ std::future<void> write_fut;
+ std::string value = "my_string";
+ bp::system(
+ "test.exe",
+ bp::std_out > in_buf,
+ bp::std_in < bp::buffer(value) > write_fut
+ );
+
+ write_fut.get();
+ in_buf.get();
+ }
+}
diff --git a/src/boost/libs/process/example/posix.cpp b/src/boost/libs/process/example/posix.cpp
new file mode 100644
index 000000000..4e937222a
--- /dev/null
+++ b/src/boost/libs/process/example/posix.cpp
@@ -0,0 +1,47 @@
+// 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 <boost/process.hpp>
+#include <boost/process/posix.hpp>
+#include <boost/process/extend.hpp>
+#include <iostream>
+#include <fstream>
+#include <unistd.h>
+#include <errno.h>
+
+namespace bp = boost::process;
+
+int main()
+{
+
+ //duplicate our pipe descriptor into literal position 4
+ bp::pipe p;
+ bp::system("test", bp::posix::fd.bind(4, p.native_sink()));
+
+
+ //close file-descriptor from explicit integral value
+ bp::system("test", bp::posix::fd.close(STDIN_FILENO));
+
+ //close file-descriptors from explicit integral values
+ bp::system("test", bp::posix::fd.close({STDIN_FILENO, STDOUT_FILENO}));
+
+ //add custom handlers
+ const char *env[2] = { 0 };
+ env[0] = "LANG=de";
+ bp::system("test",
+ bp::extend::on_setup([env](auto &e) { e.env = const_cast<char**>(env); }),
+ bp::extend::on_fork_error([](auto&, const std::error_code & ec)
+ { std::cerr << errno << std::endl; }),
+ bp::extend::on_exec_setup([](auto&)
+ { ::chroot("/new/root/directory/"); }),
+ bp::extend::on_exec_error([](auto&, const std::error_code & ec)
+ { std::ofstream ofs("log.txt"); if (ofs) ofs << errno; })
+ );
+
+}
diff --git a/src/boost/libs/process/example/start_dir.cpp b/src/boost/libs/process/example/start_dir.cpp
new file mode 100644
index 000000000..896ef8cc8
--- /dev/null
+++ b/src/boost/libs/process/example/start_dir.cpp
@@ -0,0 +1,27 @@
+// 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 <boost/process.hpp>
+#include <boost/filesystem.hpp>
+
+namespace bp = boost::process;
+
+int main()
+{
+ bp::system(
+ "test.exe",
+ bp::start_dir="../foo"
+ );
+
+ boost::filesystem::path exe = "test.exe";
+ bp::system(
+ boost::filesystem::absolute(exe),
+ bp::start_dir="../foo"
+ );
+}
diff --git a/src/boost/libs/process/example/sync_io.cpp b/src/boost/libs/process/example/sync_io.cpp
new file mode 100644
index 000000000..a861e7ab1
--- /dev/null
+++ b/src/boost/libs/process/example/sync_io.cpp
@@ -0,0 +1,28 @@
+// 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 <boost/process.hpp>
+#include <string>
+
+namespace bp = boost::process;
+
+int main()
+{
+ bp::ipstream p;
+
+ bp::child c(
+ "test.exe",
+ bp::std_out > p
+ );
+
+ std::string s;
+ std::getline(p, s);
+
+ c.wait();
+}
diff --git a/src/boost/libs/process/example/terminate.cpp b/src/boost/libs/process/example/terminate.cpp
new file mode 100644
index 000000000..7de2d8305
--- /dev/null
+++ b/src/boost/libs/process/example/terminate.cpp
@@ -0,0 +1,18 @@
+// 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 <boost/process.hpp>
+
+namespace bp = boost::process;
+
+int main()
+{
+ bp::child c("test.exe");
+ c.terminate();
+}
diff --git a/src/boost/libs/process/example/wait.cpp b/src/boost/libs/process/example/wait.cpp
new file mode 100644
index 000000000..9ebb53149
--- /dev/null
+++ b/src/boost/libs/process/example/wait.cpp
@@ -0,0 +1,34 @@
+// 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 <boost/process.hpp>
+#include <boost/asio.hpp>
+
+namespace bp = boost::process;
+
+int main()
+{
+ {
+ bp::child c("test.exe");
+ c.wait();
+ auto exit_code = c.exit_code();
+ }
+
+ {
+ boost::asio::io_context io_context;
+
+ bp::child c(
+ "test.exe",
+ io_context,
+ bp::on_exit([&](int exit, const std::error_code& ec_in){})
+ );
+
+ io_context.run();
+ }
+}
diff --git a/src/boost/libs/process/example/windows.cpp b/src/boost/libs/process/example/windows.cpp
new file mode 100644
index 000000000..98a838c8a
--- /dev/null
+++ b/src/boost/libs/process/example/windows.cpp
@@ -0,0 +1,30 @@
+// 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 <boost/process.hpp>
+#include <boost/process/windows.hpp>
+#include <iostream>
+
+#include <windows.h>
+
+namespace bp = boost::process;
+
+int main()
+{
+ bp::system("test.exe",
+ bp::windows::show);
+
+
+ bp::system("test.exe",
+ bp::on_setup([](auto &e)
+ { e.startup_info.dwFlags = STARTF_RUNFULLSCREEN; }),
+ bp::on_error([](auto&, const std::error_code & ec)
+ { std::cerr << ec.message() << std::endl; })
+ );
+}