2

I need to start an exe file from my app in C#.

The query string should look like this:

Extractor.exe "base\sql" "develop" "..\Data\System" "Grids"

This is my code:

public static void StartExtractor()
{
    System.Diagnostics.Process process = new System.Diagnostics.Process();
    process.StartInfo.FileName = OurFields.keskullPass + @"\Extractor.Deploy\Extractor.exe";
    process.StartInfo.Arguments = "\"base\\sql\" \"develop\" \"..\\Data\\System\" \"Grids\"";
    process.Start();
    process.WaitForExit();
}
Pang
  • 9,564
  • 146
  • 81
  • 122

1 Answers1

4

A simple way to start a process with arguments in C#:

Process.Start("yourapp.exe", "your arguments");

If you really need to wait for process to exit, then it becomes:

var process = Process.Start("yourapp.exe", "your arguments");

process.WaitForExit();

Usually you do not create Process object manually.

Process is defined in System.Diagnostics, so you also need to add it to your using clause.


And your problem is probably related to specific expectations of external application to arguments' format, or a mistake in concatenation of full path to exe.

To quote arguments you can do it manually as you did, or use a routine like that: How to correctly escape command line arguments in c#


More examples on how to start a process:

Community
  • 1
  • 1
quasoft
  • 5,291
  • 1
  • 33
  • 37