我有一个我想运行的 C# 程序,但是使用命令行从 cmd 运行,所以这是我的问题,我不知道如何创建命令,也不知道如何将命令中的参数发送到某个函数在那里。
您可以使用Process类来执行文件。
var fileName = "some.exe";
var arguments = "";
var info = new System.Diagnostics.ProcessStartInfo(fileName, arguments);
info.UseShellExecute = false;
info.CreateNoWindow = true;
// if you want read output
info.RedirectStandardOutput = true;
var process = new System.Diagnostics.Process { StartInfo = info };
process.Start();
var output = process.StandardOutput.ReadToEnd();
var error = process.StandardError?.ReadToEnd();