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