示例#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);
        }
示例#2
0
文件: Cmd.cs 项目: klukas/net-deploy
        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;
        }