天天看点

windows下PAI执行带命令行参数的外部命令

bool CFileBase::ExcuteCmdW(const wchar_t * CommandLine, const wchar_t * ExeName)
{
	do
	{
	    SHELLEXECUTEINFOW shell;
		memset(&shell, 0, sizeof(SHELLEXECUTEINFOW));
		shell.cbSize = sizeof(SHELLEXECUTEINFOW);
		shell.fMask = SEE_MASK_NOCLOSEPROCESS;
		shell.lpVerb = L"Open";
		shell.nShow = SW_HIDE;
		shell.lpParameters = CommandLine;
		shell.lpFile = ExeName;

		int ret = ShellExecuteExW(&shell);//ÕâÀïÈç¹ûÖ´ÐÐʧ°ÜÔõô°ìÄØ
		if (ret != 0)
		{
			if (shell.hProcess == NULL)
				break;
			WaitForSingleObject(shell.hProcess, INFINITE);
			return true;
		}
	} while (false);
	return false;
}