public bool RunRemoteCommand(string strCmdLine, out string strProcessDumpInfo) { bool fRet = true; strProcessDumpInfo = ""; try { m_iOutputLineCount = 0; m_strLastOutputLine = null; // Start the process Process process = new Process(); process.StartInfo.FileName = "cmd.exe"; process.StartInfo.WorkingDirectory = m_strCurWorkingDir; process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardInput = true; process.OutputDataReceived += new DataReceivedEventHandler(Process_OutputDataReceived); process.ErrorDataReceived += new DataReceivedEventHandler(Process_ErrorDataReceived); process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); // Write the command process.StandardInput.WriteLine(strCmdLine); process.StandardInput.Close(); process.WaitForExit(); process.Close(); m_strCurWorkingDir = m_strLastOutputLine.Substring(0, m_strLastOutputLine.Length - 1); if (m_cmdFinishHandlers != null) { Delegate[] invokeList = m_cmdFinishHandlers.GetInvocationList(); IEnumerator ie = invokeList.GetEnumerator(); while (ie.MoveNext()) { CmdFinishHandler cmdFinish = ie.Current as CmdFinishHandler; try { cmdFinish.Invoke(); } catch (Exception) { // m_cmdFinishHandlers -= cmdFinish; } } } } catch (Exception e) { strProcessDumpInfo = e.Message; fRet = false; } return(fRet); }
public void OnCmdFinish() { if (CmdFinishCallBack != null) { Delegate[] invokeList = CmdFinishCallBack.GetInvocationList(); IEnumerator ie = invokeList.GetEnumerator(); while (ie.MoveNext()) { CmdFinishHandler cmdFinish = ie.Current as CmdFinishHandler; try { cmdFinish.Invoke(); } catch (Exception) { CmdFinishCallBack -= cmdFinish; } } } }