1 /*
2  * PROJECT:     ReactOS Automatic Testing Utility
3  * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE:     Class that creates a process and redirects its output to a pipe
5  * COPYRIGHT:   Copyright 2015 Thomas Faber (thomas.faber@reactos.org)
6  */
7 
8 #include "precomp.h"
9 
10 /**
11  * Constructs a CPipedProcess object and starts the process with redirected output.
12  *
13  * @param CommandLine
14  * A std::wstring containing the command line to run.
15  *
16  * @param Pipe
17  * The CPipe instance to redirect the process's output to.
18  * Note that only the read pipe is usable after the pipe was passed to this object.
19  */
20 CPipedProcess::CPipedProcess(const wstring& CommandLine, CPipe& Pipe)
21     : CProcess(CommandLine, InitStartupInfo(Pipe))
22 {
23     Pipe.CloseWritePipe();
24 }
25 
26 /**
27  * Initializes the STARTUPINFO structure for use in CreateProcessW.
28  *
29  * @param Pipe
30  * The CPipe instance to redirect the process's output to.
31  */
32 LPSTARTUPINFOW
33 CPipedProcess::InitStartupInfo(CPipe& Pipe)
34 {
35     ZeroMemory(&m_StartupInfo, sizeof(m_StartupInfo));
36     m_StartupInfo.cb = sizeof(m_StartupInfo);
37     m_StartupInfo.dwFlags = STARTF_USESTDHANDLES;
38     m_StartupInfo.hStdInput  = GetStdHandle(STD_INPUT_HANDLE);
39     m_StartupInfo.hStdOutput = Pipe.m_hWritePipe;
40     m_StartupInfo.hStdError  = Pipe.m_hWritePipe;
41     return &m_StartupInfo;
42 }
43