Invalid Parameter when Initializing Process() running Git ssh in C#Console Application

Asked

Viewed 100 times

1

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

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’s basically the one that’s causing the error. I did a lot of research, but I couldn’t find a solution.

  • 1

    Wouldn’t it be right to pass the --login in startInfo.Arguments? That is to say: string commandString = "--login git".

  • Really, this way he understands and enters the console. Is there a possibility that I can continue using this process to give other commands from now on? (I believe this would be another question on the site, am I right? rs).

  • Of course you can continue passing other parameters. That’s why it’s called Arguments :p

1 answer

2


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

In your case, it will stay that way:

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 .

Browser other questions tagged

You are not signed in. Login or sign up in order to post.