Process.Start() and PATH environment variable

Not quite sure why the problem occurs. Though, I can think of one solution that works on my machine: var enviromentPath = System.Environment.GetEnvironmentVariable(“PATH”); Console.WriteLine(enviromentPath); var paths = enviromentPath.Split(‘;’); var exePath = paths.Select(x => Path.Combine(x, “mongo.exe”)) .Where(x => File.Exists(x)) .FirstOrDefault(); Console.WriteLine(exePath); if (string.IsNullOrWhiteSpace(exePath) == false) { Process.Start(exePath); } I did find one para which gave me … Read more

Use Process.Start with parameters AND spaces in path

Even when you use the ProcessStartInfo Class, if you have to add spaces for arguments, then the above answers won’t solve the problem. There’s a simple solution. Just add quotes around arguments. That’s all. string fileName = @”D:\Company Accounts\Auditing Sep-2014 Reports.xlsx”; System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.FileName = “Excel.exe”; startInfo.Arguments = “\”” + fileName + … Read more

How do I start a process from C#?

As suggested by Matt Hamilton, the quick approach where you have limited control over the process, is to use the static Start method on the System.Diagnostics.Process class… using System.Diagnostics; … Process.Start(“process.exe”); The alternative is to use an instance of the Process class. This allows much more control over the process including scheduling, the type of … Read more

Process.start: how to get the output?

When you create your Process object set StartInfo appropriately: var proc = new Process { StartInfo = new ProcessStartInfo { FileName = “program.exe”, Arguments = “command line arguments to your executable”, UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true } }; then start the process and read from it: proc.Start(); while (!proc.StandardOutput.EndOfStream) { string … Read more