You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace OpenAuth.App.Common
|
|
{
|
|
public class CommonData
|
|
{
|
|
/// <summary>
|
|
/// 执行cmd命令
|
|
/// </summary>
|
|
/// <param name="strDir"></param>
|
|
/// <param name="_path"></param>
|
|
public static void ExeCmdProcess(string strDir, string _path)
|
|
{
|
|
Process p = new Process();
|
|
p.StartInfo.FileName = "cmd.exe ";
|
|
p.StartInfo.UseShellExecute = false;
|
|
p.StartInfo.RedirectStandardInput = true;
|
|
p.StartInfo.RedirectStandardOutput = true;
|
|
p.StartInfo.RedirectStandardError = true;
|
|
p.StartInfo.CreateNoWindow = false;
|
|
|
|
//指定执行程序的目录
|
|
p.StartInfo.WorkingDirectory = _path;
|
|
//开始执行
|
|
p.Start();
|
|
//Console.WriteLine("command:" + strInput);
|
|
p.StandardInput.WriteLine(strDir.ToString() + "&exit");
|
|
|
|
//执行结果返回
|
|
string output = p.StandardOutput.ReadToEnd();
|
|
|
|
//等待执行完成
|
|
p.WaitForExit();
|
|
|
|
//关闭程序
|
|
p.Close();
|
|
}
|
|
|
|
}
|
|
}
|