688 bool WindowsProcess::Execute(const TString Application,
689 const std::vector<TString> Arguments, bool AWait) {
690 bool result = false;
691
692 if (FRunning == false) {
693 FRunning = true;
694
695 STARTUPINFO startupInfo;
696 ZeroMemory(&startupInfo, sizeof (startupInfo));
697 startupInfo.cb = sizeof (startupInfo);
698 ZeroMemory(&FProcessInfo, sizeof (FProcessInfo));
699
700 TString command = Application;
701
702 for (std::vector<TString>::const_iterator iterator = Arguments.begin();
703 iterator != Arguments.end(); iterator++) {
704 command += TString(_T(" ")) + *iterator;
705 }
706
707 if (::CreateProcess(Application.data(), (wchar_t*)command.data(), NULL,
708 NULL, FALSE, 0, NULL, NULL, &startupInfo, &FProcessInfo) == FALSE) {
709 TString message = PlatformString::Format(
710 _T("Error: Unable to create process %s"),
711 Application.data());
712 throw Exception(message);
713 } else {
714 if (FJob.GetHandle() != NULL) {
715 if (::AssignProcessToJobObject(FJob.GetHandle(),
716 FProcessInfo.hProcess) == 0) {
717 // Failed to assign process to job. It doesn't prevent
718 // anything from continuing so continue.
719 }
720 }
721
722 // Wait until child process exits.
723 if (AWait == true) {
724 Wait();
725 // Close process and thread handles.
726 Cleanup();
727 }
728 }
|
688 bool WindowsProcess::Execute(const TString Application,
689 const std::vector<TString> Arguments, bool AWait) {
690 bool result = false;
691
692 if (FRunning == false) {
693 FRunning = true;
694
695 STARTUPINFO startupInfo;
696 ZeroMemory(&startupInfo, sizeof (startupInfo));
697 startupInfo.cb = sizeof (startupInfo);
698 ZeroMemory(&FProcessInfo, sizeof (FProcessInfo));
699
700 TString command = Application;
701
702 for (std::vector<TString>::const_iterator iterator = Arguments.begin();
703 iterator != Arguments.end(); iterator++) {
704 command += TString(_T(" ")) + *iterator;
705 }
706
707 if (::CreateProcess(Application.data(), (wchar_t*)command.data(), NULL,
708 NULL, FALSE, 0, NULL, NULL, &startupInfo, &FProcessInfo)
709 == FALSE) {
710 TString message = PlatformString::Format(
711 _T("Error: Unable to create process %s"),
712 Application.data());
713 throw Exception(message);
714 } else {
715 if (FJob.GetHandle() != NULL) {
716 if (::AssignProcessToJobObject(FJob.GetHandle(),
717 FProcessInfo.hProcess) == 0) {
718 // Failed to assign process to job. It doesn't prevent
719 // anything from continuing so continue.
720 }
721 }
722
723 // Wait until child process exits.
724 if (AWait == true) {
725 Wait();
726 // Close process and thread handles.
727 Cleanup();
728 }
729 }
|