开发者

How to run system() with C#?

开发者 https://www.devze.com 2023-02-06 14:47 出处:网络
I\'m rewriting a Ruby program in C#. It 开发者_运维技巧has a lot of system() calls (like system(\"./program\")).

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

精彩评论

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