private static string Executecmd (String wrokdirectory, String doscommand)
{
string output = string. Empty;
if (string. IsNullOrEmpty (wrokdirectory) | | String. IsNullOrEmpty (Doscommand))
{
return output;
}
Process process = new process ();
ProcessStartInfo startinfo = new ProcessStartInfo ();
Startinfo.filename = "cmd.exe";
Startinfo.arguments = "/C" + Doscommand; Set the parameter, where "/C" means to exit immediately after executing the command
Startinfo.useshellexecute = false; Booting without using the system shell
Startinfo.redirectstandardinput = false; Do not redirect input
Startinfo.redirectstandardoutput = true; REDIRECT Output
Startinfo.createnowindow = true; Do not create a window
Startinfo.workingdirectory = wrokdirectory;
Process. StartInfo = StartInfo;
Try
{
if (process. Start ())//BEGIN Process
{
Process. Standardoutput.readtoend (); Read output stream release buffer, without this sentence, the process will wait indefinitely
Process. WaitForExit ();
}
}
catch (Exception e)
{
DEBUG.LOG ("Exception!!!");
}
return output;
}
Use of C # process