How to run a shell command from a C# program?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How to run a shell command from a C# .Net program, more like the command() function in UNIX C
 
Try System.Diagnostics.Process.Start(). For example,
System.Diagnostics.Process.Start("notepad.exe") or
System.Diagnostics.Process.Start("nda.doc") (which will start Word).

Bruce
 
Also you can create an instance of the Process class for additional info.



System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = @"C:\Windows\System32\ipconfig.exe";
p.StartInfo.Arguments = "/all";

p.Start();
p.WaitForExit(); //not necessary but sometimes needed

There's a lot more stuff you can use including redirecting the output of a
program.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top