1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
PROCESS_INFORMATION piSource, piDest;
HANDLE hPipeIn, hPipeOut;
HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
STARTUPINFOW suSource, suDest;
ZeroMemory(&suSource, sizeof(suSource));
ZeroMemory(&suDest, sizeof(suDest));
suSource.cb = suDest.cb = sizeof(STARTUPINFOW);
suSource.dwFlags = suDest.dwFlags = STARTF_USESTDHANDLES;
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = 0;
sa.bInheritHandle = TRUE;
//create a pipe
if (CreatePipe(&hPipeIn, &hPipeOut, &sa, 0) == 0)
{
return GetLastError();
}
suSource.hStdInput = hIn; //hin=STD_INPUT_HANDLE input of source = input
suSource.hStdError = suSource.hStdOutput = hPipeOut;//output and error of source = input of pipe
suDest.hStdInput = hPipeIn; //destInput = pipe output
suDest.hStdError = suDest.hStdOutput = hOut; //hout = STD_OUTPUT_HANDLE = output of destination
//to hide the new window
suDest.wShowWindow = SW_HIDE;
//open 2 process and pipe them 1 to another
//openssl proccess
std::wcout << opensslProgram << L" " << openSslFullParameters << std::endl;
LPWSTR param1 = const_cast<LPWSTR>(openSslFullParameters.c_str());
if (CreateProcess(opensslProgram.c_str(), param1, NULL, NULL, TRUE, 0, NULL, NULL, &suSource, &piSource) == 0)
{
return GetLastError();
}
CloseHandle(piSource.hThread);
//mplayer need to read from stdout of openssl
LPWSTR param2 = const_cast<LPWSTR>(mplayerParameters.c_str());
if (CreateProcess(mplayerProgram.c_str(), param2, NULL, NULL, TRUE,/*NULL*/ CREATE_NO_WINDOW, NULL, NULL, &suDest, &piDest) == 0) {//CREATE_NO_WINDOW
return GetLastError();
}
CloseHandle(piDest.hThread);
HANDLE hArray[2];
hArray[0] = piSource.hProcess;
hArray[1] = piDest.hProcess;
WaitForMultipleObjects(2, hArray, TRUE, INFINITE);
|