CMD.cs 1.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Install.Core.Common
{
    public static class CMD
    {
        public static void RunExe(string exePath, string arguments, out string output, out string error)
        {
            using (Process process = new Process())
            {
                process.StartInfo.FileName = exePath;
                process.StartInfo.Arguments = arguments;
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.CreateNoWindow = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError = true;
                process.Start();

                output = process.StandardOutput.ReadToEnd();
                error = process.StandardError.ReadToEnd();

                process.WaitForExit();
                process.Close();
            }
        }

        public static void RunExe(string exePath)
        {
            Process startProc = new Process();
            startProc.StartInfo.FileName = exePath;  //就是你要打开的文件的详细路径
            startProc.StartInfo.UseShellExecute = true;
           
            startProc.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(exePath); //就是如APGIS.Tools.exe 执行文件是在那个文件夹下。
            startProc.Start();
        }
    }
}