我正在用C#重写一个Ruby程序。它有很多system()调用(如system(“./ program”))。如何用C#运行system()?
有没有办法在C#中调用它,还是必须使用Systemm.Diagnostics.Process?
我正在用C#重写一个Ruby程序。它有很多system()调用(如system(“./ program”))。如何用C#运行system()?
有没有办法在C#中调用它,还是必须使用Systemm.Diagnostics.Process?
System.Diagnostics.Process.Start是Ruby中与.NET等价的system()
。
还是必须使用Systemm.Diagnostics.Process?
您可以在文件顶部添加using System.Diagnostics;
。然后它变成Process.Start("program.exe");
。
如果您不想打扰分裂参数并设置ProcessStartInfo
,则可以简单地添加对Microsoft.VisualBasic程序集的引用并使用Microsoft.VisualBasic.Interaction.Shell
static method。
using Microsoft.VisualBasic;
Interaction.Shell("format c: /q");