All pastes #521049 Raw Edit

Piping output in WIN32API

public c v1 · immutable
#521049 ·published 2007-05-30 02:57 UTC
rendered paste body
SECURITY_ATTRIBUTES sa = {12, NULL, TRUE}; // Let child process inherit handles (specifically hStdoutWrite)HANDLE hPipeRead, hPipeWrite;if (!CreatePipe(&hPipeRead, &hPipeWrite, &sa, 0)){	// moan, bitch, and whine}STARTUPINFO si = {68, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES, 0, 0, NULL, NULL, NULL};si.hStdOutput = hPipeWrite;si.hStdError = hPipeWrite;PROCESS_INFORMATION pi;if (!CreateProcess(NULL, "cmd /c dir", &sa, &sa, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi)){	// moan, bitch, and whine}CloseHandle(hPipeWrite);// then use ReadFile to read from hPipeRead