我在 DOS 中有大约 7 个命令,我想在我的 C# 程序中运行它们。我可以这样做吗:
System.Diagnostics.Process.Start("cmd.exe", "my more commands here");
? 编辑: 我正在制作将运行 g++ 的小应用程序。这现在正确吗?:
System.Diagnostics.Process.Start("cmd.exe", "/k cd C:\\Alps\\compiler\\ /k g++ C:\\Alps\\" + project_name + "\\Debug\\Main.cpp");
编译命令:
g++ -c C:\Alps\here_is_projectname\Debug\Main.cpp -o main.o
最佳答案
cmd.exe /k <command>
cmd.exe /c <command>
都有效。
/k
将执行命令并留下一个空提示(如果您只想执行以获取反馈,则可能不太适合您的应用程序。)/c
将执行命令并在完成后关闭窗口。
如果你想从特定目录执行命令,你可以这样做:
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = new System.Diagnostics.ProcessStartInfo("cmd.exe");
p.StartInfo.Arguments = String.Format(@"/c g++ ""C:\Alps\{0}\Debug\Main.cpp""", project_name);
p.StartInfo.WorkingDirectory = @"C:\Alps\compiler";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.ErrorDialog = false;
p.Start();
关于c# - C#中如何使用更多的DOS命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6999201/