Execute system command in C#

Execute system commands in C# using Process and ProcessStartInfo classes.

Code

void ExecuteCommand(String command)
{
	Process process = new Process();
	ProcessStartInfo startInfo = new ProcessStartInfo();
	startInfo.WindowStyle = ProcessWindowStyle.Hidden;
	startInfo.FileName = "cmd.exe";
	startInfo.Arguments = "/C " + command;
	process.StartInfo = startInfo;
	process.Start();
	process.BeginOutputReadLine();
	process.WaitForExit();
}

Usage

ExecuteCommand("notepad.exe");
Categories: C# Tags: , , ,
%d bloggers like this: