作为一个有趣的项目,我尝试通过C#通过git-cmd.exe进程运行多个命令。
我有这个代码来运行多个命令:
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}'
这样运行正常,但是当我尝试运行以下命令时,我收到了几条消息。
命令(https://stackoverflow.com/a/33656490/1671161):
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
消息:
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();
查看BitBuckets API文档,400返回状态意味着&#34;如果输入文档无效,或者调用者没有在目标帐户下创建存储库的权限。&#34;不幸的是,我无法找到在git-cmd.exe中运行的命令的正确格式。
该命令在Git Bash中运行正常,所以我尝试运行Git bash过程:
{{1}}
但是,这会打开一个Git Bash窗口,并且不会执行我的命令。老实说,我希望程序与git-cmd.exe进程完全一样。因此,不打开新窗口,而是在已打开的窗口中执行所有命令,并显示输出。
所以,我的问题是:如何在我的git-cmd.exe进程中运行CURL命令才能成功运行?或者,我应该如何在程序窗口中运行git-bash.exe进程?
答案 0 :(得分:0)
将ProcessStartInfo上的CreateNoWindow
属性设置为true,它将显示为git在您自己的应用程序中运行。这两种方式都会启动子进程,但CreateNoWindow
设置为true
会阻止控制台窗口显示。