diff options
author | Adam Mitz <mitza@ociweb.com> | 2015-02-10 14:35:07 -0600 |
---|---|---|
committer | Adam Mitz <mitza@ociweb.com> | 2015-02-10 14:37:52 -0600 |
commit | 35cce6f3e5dffa216f3bf064ff45454d3e7c222d (patch) | |
tree | 35f4cfea223343adc40b4d2d3fd3b8ba6b68b7bb /ACE/ace/Process.cpp | |
parent | d6653a19bcdd55090dfade3f30cfbf648777b22f (diff) | |
download | ATCD-35cce6f3e5dffa216f3bf064ff45454d3e7c222d.tar.gz |
ACE_Process on Windows:
Allow redirection of child's stdout/stderr when there is no
stdin handle available (for example when running in a service).
TAO_IDL drv_preproc: check for errors from ACE_Process
Diffstat (limited to 'ACE/ace/Process.cpp')
-rw-r--r-- | ACE/ace/Process.cpp | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/ACE/ace/Process.cpp b/ACE/ace/Process.cpp index f10c11c358c..2286d688e95 100644 --- a/ACE/ace/Process.cpp +++ b/ACE/ace/Process.cpp @@ -1141,32 +1141,47 @@ ACE_Process_Options::set_handles (ACE_HANDLE std_in, if (std_err == ACE_INVALID_HANDLE) std_err = ACE_STDERR; - if (!::DuplicateHandle (::GetCurrentProcess (), - std_in, - ::GetCurrentProcess (), - &this->startup_info_.hStdInput, - 0, - TRUE, - DUPLICATE_SAME_ACCESS)) - return -1; + // STD handles may have value 0 (not ACE_INVALID_HANDLE) if there is no such + // handle in the process. This was observed to occur for stdin in console + // processes that were launched from services. In this case we need to make + // sure not to return -1 from setting std_in so that we can process std_out + // and std_err. - if (!::DuplicateHandle (::GetCurrentProcess (), - std_out, - ::GetCurrentProcess (), - &this->startup_info_.hStdOutput, - 0, - TRUE, - DUPLICATE_SAME_ACCESS)) - return -1; + if (std_in) + { + if (!::DuplicateHandle (::GetCurrentProcess (), + std_in, + ::GetCurrentProcess (), + &this->startup_info_.hStdInput, + 0, + TRUE, + DUPLICATE_SAME_ACCESS)) + return -1; + } - if (!::DuplicateHandle (::GetCurrentProcess (), - std_err, - ::GetCurrentProcess (), - &this->startup_info_.hStdError, - 0, - TRUE, - DUPLICATE_SAME_ACCESS)) - return -1; + if (std_out) + { + if (!::DuplicateHandle (::GetCurrentProcess (), + std_out, + ::GetCurrentProcess (), + &this->startup_info_.hStdOutput, + 0, + TRUE, + DUPLICATE_SAME_ACCESS)) + return -1; + } + + if (std_err) + { + if (!::DuplicateHandle (::GetCurrentProcess (), + std_err, + ::GetCurrentProcess (), + &this->startup_info_.hStdError, + 0, + TRUE, + DUPLICATE_SAME_ACCESS)) + return -1; + } #else /* ACE_WIN32 */ this->stdin_ = ACE_OS::dup (std_in); this->stdout_ = ACE_OS::dup (std_out); |