Ejemplo n.º 1
0
        public CmdResult Run()
        {
            Process proc = new Process();

            proc.StartInfo.FileName  = "cmd.exe";
            proc.StartInfo.Arguments = "/c " + _command;
            if (!string.IsNullOrEmpty(_runFrom))
            {
                proc.StartInfo.WorkingDirectory = _runFrom;
            }

            proc.StartInfo.UseShellExecute        = false;
            proc.StartInfo.CreateNoWindow         = true;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.RedirectStandardError  = true;

            proc.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
            proc.ErrorDataReceived  += new DataReceivedEventHandler(proc_ErrorDataReceived);

            WriteLog(_command);

            proc.Start();

            proc.BeginOutputReadLine();
            proc.BeginErrorReadLine();

            proc.WaitForExit();

            var result = new CmdResult(_command, proc.ExitCode, _output.ToString());

            proc.Close();

            WriteLog("exit code: " + result.ExitCode);
            return(result);
        }
Ejemplo n.º 2
0
        public CmdResult Run()
        {
            Process proc = new Process();

            proc.StartInfo.FileName = "cmd.exe";
            proc.StartInfo.Arguments = "/c " + _command;
            if(!string.IsNullOrEmpty(_runFrom)) proc.StartInfo.WorkingDirectory = _runFrom;

            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.CreateNoWindow = true;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.RedirectStandardError = true;

            proc.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
            proc.ErrorDataReceived += new DataReceivedEventHandler(proc_ErrorDataReceived);

            WriteLog(_command);

            proc.Start();

            proc.BeginOutputReadLine();
            proc.BeginErrorReadLine();

            proc.WaitForExit();

            var result = new CmdResult(_command, proc.ExitCode, _output.ToString());
            proc.Close();

            WriteLog("exit code: " + result.ExitCode);
            return result;
        }