天天看點

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;
}