我试图弄清楚如何从在 IIS 7/.Net 4.5 上运行的 C# 运行 bash 命令。
我一直在网上搜索,很多答案都假设您已经安装/就位了某些东西。
我已经有了Git 1.9.4.msysgit.2
与 Git Bash 和 Git Giu 一起安装。我正在寻求一些帮助,了解我还需要安装什么才能运行最简单的 bash 命令。以及如何运行它。
我看过类似的帖子bash 管道 - 我正在尝试从 C# 调用脚本 https://stackoverflow.com/questions/15586424/bash-pipes-i-am-trying-to-call-script-from-c-sharp但这使用cygwin
。如果没有它,我可以做同样的事情吗?如果可以,我该怎么做?
Goal
如果我上面的问题没有意义或者似乎提出了单独的问题,那么这就是我的最终目标。我正在尝试编写自己的服务器端 git hook。当开发商pushes
他们提交到我们的 GitHub 存储库,我希望 GitHub 调用我们的回调 URL。我希望我的回调 url 运行git pull
命令更新我们的staging
服务器上有刚刚推送的内容。
我根据我之前提出的问题提出了这个问题GitHub - 使用远程服务器设置自动部署 https://stackoverflow.com/questions/28485281/github-setup-auto-deployment-with-remote-server/28485470?noredirect=1#comment45293201_28485470。根据那里的答案,我正在尝试运行一个简单的命令,但可以对命令进行硬编码,或者将其放入脚本中并运行它,例如:cd $REPO_DIR && git pull origin $branch_name
.
我知道 Jenkins 和其他软件,但我想自己执行这些命令,而不是安装其他软件。
如果需要更多信息,请随时询问。
Update 1
因此,根据下面的一些答案,我得出了以下结论
using System.Diagnostics;
Process process = new Process();
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
processStartInfo.FileName = @"C:\Program Files (x86)\Git\bin\bash.exe";
processStartInfo.WorkingDirectory = @"C:\myrepo\mysite";
processStartInfo.Arguments = "git status";
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardError = true;
processStartInfo.UseShellExecute = false;
process.StartInfo = processStartInfo;
process.Start();
String error = process.StandardError.ReadToEnd();
String output = process.StandardOutput.ReadToEnd();
ViewBag.Error = error;
ViewBag.Ouput = output;
通过上面的代码我得到"C:/Program Files (x86)/Git/bin/bash.exe": git: No such file or directory
。我知道exe就在那里。我做错了什么?
Update 2
根据@SurgeonofDeath 评论,我关注了这篇文章http://blog.countableset.ch/2012/06/07/adding-git-to-windows-7-path/ http://blog.countableset.ch/2012/06/07/adding-git-to-windows-7-path/并将 Git 的路径添加到我的环境变量中。但是我仍然遇到同样的问题。有任何想法吗?
Thanks.