As a fun project I'm trying to run several commands through a git-cmd.exe process via C#.
I have this code to run multiple commands:
var info = new ProcessStartInfo(@"C:\Program Files\Git\git-cmd.exe");
info.RedirectStandardInput = true;
info.UseShellExecute = false;
var gitProcess = new Process { StartInfo = info };
gitProcess.Start();
using (StreamWriter sw = gitProcess.StandardInput)
{
// commands here
}
gitProcess.WaitForExit();
This runs fine, but when I try to run the following command, I am getting several messages.
Command (https://stackoverflow.com/a/33656490/1671161):
curl -X POST -v -u username:password https://api.bitbucket.org/2.0/repositories/TeamName/reponame -H "Content-Type: application/json" -d '{"scm": "git", "is_private": true, "fork-policy": "no_public_forks", "has_issues": true}'
Messages:
Note: Unnecessary use of -X or --request, POST is already inferred.
* timeout on name lookup is not supported
* Trying 2401:1d80:1010::153...
* Connected to api.bitbucket.org (2401:1d80:1010::153) port 443 (#0)
#more messages, seems OK to me so far, but then this:
Connection state changed (MAX_CONCURRENT_STREAMS updated)!
* We are completely uploaded and fine
* HTTP 1.0, assume close after body
< HTTP/2 400
< server: nginx/1.6.2
< vary: Authorization, Cookie
< content-type: text/plain
< strict-transport-security: max-age=31536000
< date: Wed, 10 Aug 2016 17:34:57 GMT
< x-served-by: app-112
< x-static-version: 89c5b48218a9
< etag: "825644f747baab2c00e420dbbc39e4b3"
< x-render-time: 0.0194010734558
< x-accepted-oauth-scopes: repository:admin
< x-version: 89c5b48218a9
< x-request-count: 459
< x-frame-options: SAMEORIGIN
< content-length: 11
<
Bad Request* Closing connection 0
* TLSv1.2 (OUT), TLS alert, Client hello (1):
Note: Unnecessary use of -X or --request, POST is already inferred.
* Rebuilt URL to: git,/
* timeout on name lookup is not supported
* getaddrinfo(3) failed for git,:80
* Couldn't resolve host 'git,'
* Closing connection 1
Looking up BitBuckets API documentation, the 400 return state means "If the input document was invalid, or if the caller lacks the privilege to create repositories under the targeted account." Unfortunately, I couldn't find out the right format for the command to run in git-cmd.exe.
The command runs fine in Git Bash, so I tried to run a Git bash process:
var gitbashinfo = new ProcessStartInfo(@"C:\Program Files\Git\git-bash.exe");
gitbashinfo.RedirectStandardInput = true;
gitbashinfo.UseShellExecute = false;
var gitbashProcess = new Process { StartInfo = gitbashinfo };
gitbashProcess.Start();
using (StreamWriter sw = gitbashProcess.StandardInput)
{
// The command
}
gitbashProcess.WaitForExit();
But, this opens a Git Bash window, and does not execute my command. I honestly expected the program to do the exact same thing as I did with the git-cmd.exe process. Hence, not opening a new window, but execute all commands in the already opened window, and show the output as well.
So, my question is: how can I run the CURL command to run successfully in my git-cmd.exe process? OR, how should I run the git-bash.exe process inside my program window?