Reputation: 6817
I am having this problem. My ShellExecute
works fine, the output is a PNG image file. The problem is this process take some time (seconds) for the file to be produced. Meanwhile, my result
here has already executed but it produce error message because the PNG file from ShellExecute
does not exist yet. How to make sure that the file is exist first, then after that result
can execute.
ShellExecute(0,
_T("open"),
_T("c:\\convert.exe"),
full,
0,
SW_HIDE);
result = ExecuteExternalProgramCompare(L"c.png", L"t.png"); // this line always gives error because the file c.png is not produce yet by shellexecute above.
update: My attempt to convert to ShellexecuteEx.
SHELLEXECUTEINFO info = {0};
info.cbSize = sizeof(SHELLEXECUTEINFO);
info.fMask = SEE_MASK_NOCLOSEPROCESS;
info.lpFile = _T("c:\\convert.exe");
info.lpParameters = full;
info.nShow = SW_HIDE;
Upvotes: 0
Views: 245
Reputation: 2013
You should use ShellExecuteEx. This will allow you to get a handle on the called process, so that you can wait for the process to end.
SHELLEXECUTEINFO info = {0};
info.cbSize = sizeof(SHELLEXECUTEINFO);
info.fMask = SEE_MASK_NOCLOSEPROCESS;
info.lpVerb = _T("open");
info.lpFile = _T("c:\\convert.exe");
info.lpParameters = full;
info.lpDirectory = NULL;
info.nShow = SW_HIDE;
if (ShellExecuteEx (&info))
{
WaitForSingleObject (info.hProcess, INFINITE);
}
Upvotes: 1