int my_CreateProcess(){ BOOL run_pipe;
PROCESS_INFORMATION pi; STARTUPINFO si; BOOL ret = FALSE; DWORD flags = CREATE_NO_WINDOW;
_unlink("D:/out/output.log");
char pBuffer[210]; SECURITY_ATTRIBUTES sa; sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = TRUE; HANDLE hReadPipe, hWritePipe; run_pipe=CreatePipe(&hReadPipe, &hWritePipe, &sa, 0); printf("run_pipe=%d\n", run_pipe);
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION)); ZeroMemory(&si, sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); si.dwFlags |= STARTF_USESTDHANDLES; si.hStdInput = NULL; si.hStdError = hWritePipe; si.hStdOutput = hWritePipe;
TCHAR cmd[] = TEXT("ffmpeg -i D:\\123.mp4 -vf reverse D:\\out\\out1.mp4");
ret = CreateProcess(NULL, cmd, NULL, NULL, TRUE, flags, NULL, NULL, &si, &pi);
if (ret) { while (true) { DWORD ExitCode = 0; //判断进程是否执行结束 GetExitCodeProcess(pi.hProcess, &ExitCode); if (ExitCode == STILL_ACTIVE) //正在运行 { DWORD RSize=0; BOOL run_s=0; run_s =ReadFile(hReadPipe, pBuffer,200,&RSize,NULL); pBuffer[RSize] = '\0'; printf("返回结果:%d,%d,%s\n", run_s, RSize, pBuffer); } else //结束 { printf("执行完毕...\n"); break; } } //WaitForSingleObject(pi.hProcess, INFINITE); printf("执行成功....\n"); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); return 0; } printf("执行失败....\n"); return -1;}
评论