更新时间:2021-12-03 22:24:46
您可以使用C#中的Process类执行CMD命令
you can execute CMD commands using Process class in C#
Process p = new Process();
p.StartInfo = new ProcessStartInfo("cmd.exe");
p.StartInfo.Arguments = 'findstr /x /c:"computer help" *.txt';
p.StartInfo.WorkingDirectory = workingDirectory;
//p.StartInfo.CreateNoWindow = true;
p.StartInfo.ErrorDialog = true;
//p.StartInfo.RedirectStandardInput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
p.WaitForExit();
p.Close();
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C findstr /c:" + "\"" + textfilter + "\"" + " " + sourcefilename + " > " + outputfilename;
startInfo.WorkingDirectory = directory;
process.StartInfo = startInfo;
process.Start();