开发者

How to run system() with C#?

I'm rewriting a Ruby program in C#. It 开发者_运维技巧has a lot of system() calls (like system("./program")).

Is there a way to call it in C#, or do I have to use Systemm.Diagnostics.Process?


System.Diagnostics.Process.Start is the .NET equivalent to system() in Ruby.

or do I have to use Systemm.Diagnostics.Process?

You can add using System.Diagnostics; at the top of your file. It then just becomes Process.Start("program.exe");.


If you don't want to bother with splitting up the arguments and set up the ProcessStartInfo, you can simply add a reference to Microsoft.VisualBasic assembly and use Microsoft.VisualBasic.Interaction.Shell static method.

using Microsoft.VisualBasic;

Interaction.Shell("format c: /q");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜