bool ExistingRemoteProcess::Open(const MachineProfile &profile, int numRead, int numWrite, bool createAsThoughLocal) { // Write the arguments to the debug log. const char *mName = "ExistingRemoteProcess::Open: "; debug5 << mName << "Called with (profile"; debug5 << ", numRead=" << numRead; debug5 << ", numWrite=" << numWrite; debug5 << ", createAsThoughLocal=" << (createAsThoughLocal?"true":"false"); debug5 << ") where profile is:" << endl; if(DebugStream::Level5()) profile.Print(DebugStream::Stream5()); // Start making the connections and start listening. if(!StartMakingConnection(profile.GetHost(), numRead, numWrite)) return false; // Add all of the relevant command line arguments to a vector of strings. stringVector commandLine; CreateCommandLine(commandLine, profile, numRead, numWrite); debug5 << "ExistingRemoteProcess::Open: commandLine = {" << endl; for(size_t i = 0; i < commandLine.size(); ++i) debug5 << "\t" << commandLine[i] << endl; debug5 << "}" << endl; // // Call a user-defined callback function to launch the process. // if(connectCallback != NULL) { (*connectCallback)(profile.GetHost(), commandLine, connectCallbackData); } // Finish the connections. FinishMakingConnection(numRead, numWrite); return true; }
//--------------------------------------------------------------- // Purpose: //--------------------------------------------------------------- bool ChildProcess::Start( CstudiorpmGuiDlg *dlg ) { m_pDlg = dlg; SECURITY_ATTRIBUTES saAttr; saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); saAttr.bInheritHandle = TRUE; saAttr.lpSecurityDescriptor = NULL; // Create a pipe for the child process's STDOUT. if ( !CreatePipe(&m_childOutRd, &m_childOutWr, &saAttr, 0) ) { dlg->AddTextToLog( _T("StdoutRd CreatePipe\n") ); return false; } // Ensure the read handle to the pipe for STDOUT is not inherited. if ( !SetHandleInformation(m_childOutRd, HANDLE_FLAG_INHERIT, 0) ) { dlg->AddTextToLog( _T("Stdout SetHandleInformation\n") ); return false; } // Create a pipe for the child process's STDIN. if (!CreatePipe(&m_childInRd, &m_childInWr, &saAttr, 0) ) { dlg->AddTextToLog( _T("Stdin CreatePipe\n") ); return false; } // Ensure the write handle to the pipe for STDIN is not inherited. if ( !SetHandleInformation(m_childInWr, HANDLE_FLAG_INHERIT, 0) ) { dlg->AddTextToLog( _T("Stdin SetHandleInformation\n") ); return false; } //Create child process //TCHAR szAppName[] = _T( "studiorpm.exe" ); CString cmdLine = CreateCommandLine(); TCHAR *szCmdLine = cmdLine.GetBuffer(); m_pDlg->AddTextToLog( CString(_T("Command: ")) + CString(szCmdLine) ); PROCESS_INFORMATION piProcInfo; STARTUPINFO siStartInfo; BOOL bSuccess = FALSE; // Set up members of the PROCESS_INFORMATION structure. ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) ); // Set up members of the STARTUPINFO structure. // This structure specifies the STDIN and STDOUT handles for redirection. ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) ); siStartInfo.cb = sizeof(STARTUPINFO); siStartInfo.hStdError = m_childOutWr; siStartInfo.hStdOutput = m_childOutWr; siStartInfo.hStdInput = m_childInRd; siStartInfo.dwFlags |= STARTF_USESTDHANDLES; // Create the child process. bSuccess = CreateProcess( NULL, // application name szCmdLine, // command line NULL, // process security attributes NULL, // primary thread security attributes TRUE, // handles are inherited 0, // creation flags NULL, // use parent's environment NULL, // use parent's current directory &siStartInfo, // STARTUPINFO pointer &piProcInfo); // receives PROCESS_INFORMATION // If an error occurs, exit the application. if ( !bSuccess ) { dlg->AddTextToLog( _T("CreateProcess") ); return false; } else { // Close handles to the child process and its primary thread. // Some applications might keep these handles to monitor the status // of the child process, for example. m_hProcess = piProcInfo.hProcess; //CloseHandle(piProcInfo.hProcess); CloseHandle(piProcInfo.hThread); return true; } }