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