Invalid parameter when Initializing Process () that executes Git ssh in Console Application from C #

1

I'm trying to make a Console Application in C # with some command options to run in Git ssh. The Git ssh executable is in the following path: C: / Program Files (x86) /Git/bin/sh.exe, and I'm trying to run a simple command like this:

string pathGit = "\"C:\Program Files (x86)\Git\bin\sh.exe\" --login";
string commandString = "git";

Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = pathGit;
startInfo.Arguments = commandString;
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
process.StartInfo = startInfo;
process.Start();

The "--login" in front of the path is required to actually enter the Git console, but it is basically the one that is causing the error. I researched a lot, but I could not find a solution.

    
asked by anonymous 12.04.2017 / 14:30

1 answer

2

When using ProcessStartInfo , you must pass the parameters in the Arguments , all required.

In your case, it will look like this:

string pathGit = "\"C:\Program Files (x86)\Git\bin\sh.exe\"";
string commandString = "--login git";

Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = pathGit;
startInfo.Arguments = commandString;
...

Here has an example of several parameters used in .

    
12.04.2017 / 15:42