Information Systems



How do I call a console app from a windows program?

Here's how I call ffmpeg from a windows app.

HANDLE read, write;

SECURITY_ATTRIBUTES sec;
ZeroMemory(&sec,sizeof(sec));
sec.nLength = sizeof(sec);
sec.bInheritHandle = TRUE;

CreatePipe(&read,&write,&sec,0);

STARTUPINFO si;
ZeroMemory(&si,sizeof(si));

PROCESS_INFORMATION pi;
ZeroMemory(&pi,sizeof(pi));
si.cb=sizeof(si);
si.dwFlags=STARTF_USESTDHANDLES;
si.hStdInput=NULL;
si.hStdOutput=write;
si.hStdError=write;

std::string cl = "c:/ffmpeg -y -i c:/chicken.wmv -vcodec wmv2 c2.wmv";
std::string dir = "c:/";
BOOL bOk = CreateProcess(NULL, (char*) cl.c_str(), NULL, NULL, TRUE,
NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW,
NULL, dir.c_str(), &si, &pi);

CloseHandle(write);

char buff[255];
DWORD l;
BOOL r;
std::string s;
do
{
r = ReadFile(read,buff,100,&l,0);
s += buff;
} while(r);