forked from itdos/Dos.Common
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCmdHelper.cs
More file actions
38 lines (37 loc) · 1.02 KB
/
Copy pathCmdHelper.cs
File metadata and controls
38 lines (37 loc) · 1.02 KB
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
using System;
using System.Diagnostics;
using System.IO;
namespace Dos.Common
{
/// <summary>
/// Dos cmd命令执行帮助类
/// </summary>
public class CmdHelper
{
/// <summary>
/// 运行dos命令
/// </summary>
/// <Param name="command"></Param>
/// <returns></returns>
public static string Run(string command)
{
string str = "";
ProcessStartInfo startInfo = new ProcessStartInfo("cmd", "/c " + command)
{
RedirectStandardOutput = true,
UseShellExecute = false,
RedirectStandardError = true,
CreateNoWindow = true
};
using (Process process = Process.Start(startInfo))
{
using (StreamReader reader = process.StandardOutput)
{
str = reader.ReadToEnd();
}
process.WaitForExit();
}
return str.Trim();
}
}
}