• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef BOOST_PROCESS_WINDOWS_SHELL_PATH_HPP
11 #define BOOST_PROCESS_WINDOWS_SHELL_PATH_HPP
12 
13 #include <boost/process/detail/config.hpp>
14 #include <system_error>
15 #include <boost/filesystem/path.hpp>
16 #include <boost/winapi/basic_types.hpp>
17 #include <boost/winapi/get_system_directory.hpp>
18 
19 namespace boost { namespace process { namespace detail { namespace windows {
20 
shell_path()21 inline boost::filesystem::path shell_path()
22 {
23     ::boost::winapi::WCHAR_ sysdir[260];
24     unsigned int size = ::boost::winapi::get_system_directory(sysdir, sizeof(sysdir));
25     if (!size)
26         throw_last_error("GetSystemDirectory() failed");
27 
28     boost::filesystem::path p = sysdir;
29     return p / "cmd.exe";
30 }
31 
shell_path(std::error_code & ec)32 inline boost::filesystem::path shell_path(std::error_code &ec) noexcept
33 {
34 
35     ::boost::winapi::WCHAR_ sysdir[260];
36     unsigned int size = ::boost::winapi::get_system_directory(sysdir, sizeof(sysdir));
37     boost::filesystem::path p;
38     if (!size)
39         ec = std::error_code(
40                 ::boost::winapi::GetLastError(),
41                 std::system_category());
42     else
43     {
44         ec.clear();
45         p = sysdir;
46         p /= "cmd.exe";
47     }
48     return p;
49 }
50 
51 }}}}
52 
53 #endif
54