2021年1月20日星期三

How to run .bat file in c# (contain batch file) [duplicate]

I want to make if i press button it will delete all temp folder insiders(for better fps or so) i have .bat code but i found every page like this,

Code copied from Executing Batch File in C# answer by steinar:

static void ExecuteCommand(string command)  {      int exitCode;      ProcessStartInfo processInfo;      Process process;        processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);      processInfo.CreateNoWindow = true;      processInfo.UseShellExecute = false;      // *** Redirect the output ***      processInfo.RedirectStandardError = true;      processInfo.RedirectStandardOutput = true;        process = Process.Start(processInfo);      process.WaitForExit();        // *** Read the streams ***      // Warning: This approach can lead to deadlocks, see Edit #2      string output = process.StandardOutput.ReadToEnd();      string error = process.StandardError.ReadToEnd();        exitCode = process.ExitCode;        Console.WriteLine("output>>" + (String.IsNullOrEmpty(output) ? "(none)" : output));      Console.WriteLine("error>>" + (String.IsNullOrEmpty(error) ? "(none)" : error));      Console.WriteLine("ExitCode: " + exitCode.ToString(), "ExecuteCommand");      process.Close();  }    static void Main()  {      ExecuteCommand("echo testing");  }  

I can only run single command. I want run many line. How can i do that?

https://stackoverflow.com/questions/65819979/how-to-run-bat-file-in-c-sharp-contain-batch-file January 21, 2021 at 09:31AM

没有评论:

发表评论