wait_for_exit.hpp
Go to the documentation of this file.
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#pragma once
11
13#include <boost/system/error_code.hpp>
14
15#include <Windows.h>
16
18{
19
20 template <class Process>
21 inline DWORD
22 wait_for_exit(const Process& p)
23 {
24 if (::WaitForSingleObject(p.process_handle(), INFINITE) == WAIT_FAILED)
25 {
26 BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("WaitForSingleObject() failed");
27 }
28
29 DWORD exit_code;
30 if (!::GetExitCodeProcess(p.process_handle(), &exit_code))
31 {
32 BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("GetExitCodeProcess() failed");
33 }
34
35 return exit_code;
36 }
37
38 template <class Process>
39 inline DWORD
40 wait_for_exit(const Process& p, boost::system::error_code& ec)
41 {
42 DWORD exit_code = 1;
43
44 if (::WaitForSingleObject(p.process_handle(), INFINITE) == WAIT_FAILED)
45 {
46 BOOST_PROCESS_RETURN_LAST_SYSTEM_ERROR(ec);
47 }
48 else if (!::GetExitCodeProcess(p.process_handle(), &exit_code))
49 {
50 BOOST_PROCESS_RETURN_LAST_SYSTEM_ERROR(ec);
51 }
52 else
53 {
54 ec.clear();
55 }
56
57 return exit_code;
58 }
59
60} // namespace boost::process::windows
Defines various macros.
DWORD wait_for_exit(const Process &p)