static void printOutputData(String data) { if (data != null) { if (outputLines > 0) { Console.Write(Environment.NewLine); } // Print output from git, converting WSL paths to Windows equivalents. Console.Write(PathConverter.convertPathFromLinuxToWindows(data)); outputLines++; } }
static void executeGitWithArgs(String bashPath, string[] args) { if (!File.Exists(bashPath)) { Console.Write("[-] Error: bash.exe not found."); return; } ProcessStartInfo bashInfo = new ProcessStartInfo(); bashInfo.FileName = Path.Combine(bashPath); // Loop through args and pass them to git executable StringBuilder argsBld = new StringBuilder(); argsBld.Append(" --login -c \"git"); for (int i = 0; i < args.Length; i++) { argsBld.Append(" " + PathConverter.convertPathFromWindowsToLinux(args[i])); } argsBld.Append("\""); bashInfo.Arguments = argsBld.ToString(); bashInfo.UseShellExecute = false; bashInfo.RedirectStandardOutput = true; bashInfo.RedirectStandardError = true; bashInfo.CreateNoWindow = true; var proc = new Process { StartInfo = bashInfo }; proc.OutputDataReceived += CaptureOutput; proc.ErrorDataReceived += CaptureError; proc.Start(); proc.BeginOutputReadLine(); proc.BeginErrorReadLine(); proc.WaitForExit(); }