12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ShareWifi.Utils
- {
- class Shell
- {
-
-
-
-
- public static string RunCmd(string cmd)
- {
- Process proc = new Process();
- proc.StartInfo.CreateNoWindow = true;
- proc.StartInfo.FileName = "cmd.exe";
- proc.StartInfo.UseShellExecute = false;
- proc.StartInfo.RedirectStandardError = true;
- proc.StartInfo.RedirectStandardInput = true;
- proc.StartInfo.RedirectStandardOutput = true;
- proc.Start();
- proc.StandardInput.WriteLine(cmd);
- proc.StandardInput.WriteLine("exit");
- proc.StandardInput.AutoFlush = true;
- string outStr = proc.StandardOutput.ReadToEnd();
- proc.WaitForExit();
- proc.Close();
- return outStr;
- }
-
-
-
-
-
- public static void RunProgram(string programName, string cmd)
- {
- Process proc = new Process();
- proc.StartInfo.CreateNoWindow = true;
- proc.StartInfo.FileName = programName;
- proc.StartInfo.UseShellExecute = false;
- proc.StartInfo.RedirectStandardError = true;
- proc.StartInfo.RedirectStandardInput = true;
- proc.StartInfo.RedirectStandardOutput = true;
- proc.Start();
- if (cmd.Length != 0)
- {
- proc.StandardInput.WriteLine(cmd);
- }
- proc.Close();
- }
-
-
-
-
- public static void RunProgram(string programName)
- {
- RunProgram(programName, "");
- }
- }
- }
|