C# 在ASP.NETWeb应用程序中使用Git命令运行批处理文件

C# 在ASP.NETWeb应用程序中使用Git命令运行批处理文件,c#,asp.net,git,batch-file,C#,Asp.net,Git,Batch File,我使用web应用程序创建了一个批处理文件,以提交我的文件并将其推送到Git存储库中,如下所示: git status git pull git add "file.properties" "file.yaml" "file_metric.yaml" git commit -m "Test Message" git push git状态 吉特拉力 git add file.properties file.yaml file\u metric.yaml git提交-m测试消息 git推送 我在W

我使用web应用程序创建了一个批处理文件,以提交我的文件并将其推送到Git存储库中,如下所示:

git status
git pull
git add "file.properties" "file.yaml" "file_metric.yaml"
git commit -m "Test Message"
git push
git状态
吉特拉力
git add file.properties file.yaml file\u metric.yaml
git提交-m测试消息
git推送
我在Web应用程序中通过单击按钮调用此批处理文件

我的代码如下:

git status
git pull
git add "file.properties" "file.yaml" "file_metric.yaml"
git commit -m "Test Message"
git push
//**文件已创建,现在调用批处理文件。
//获取完整的文件路径
字符串strFilePath=sPathName;
//创建ProcessInfo对象
System.Diagnostics.ProcessStartInfo psi=新的System.Diagnostics.ProcessStartInfo(“cmd.exe”);
psi.UseShellExecute=false;
psi.WorkingDirectory=Path.GetDirectoryName(strFilePath);
psi.0输出=真;
psi.INPUT=真;
psi.error=true;
psi.WorkingDirectory=logFolderPath;
//开始这个过程
System.Diagnostics.Process proc=系统.诊断.流程.启动(psi);
//打开批处理文件进行读取
System.IO.StreamReader strm=System.IO.File.OpenText(strFilePath);
//连接输出以进行读取
System.IO.StreamReader sOut=过程标准输出;
//附上书面报告
System.IO.StreamWriter sIn=过程标准输入;
//将批处理文件的每一行写入标准输入
while(strm.Peek()!=-1)
{
sIn.WriteLine(strm.ReadLine());
}
strm.Close();
//退出CMD.EXE
字符串stEchoFmt=“#{0}运行成功。正在退出”;
sIn.WriteLine(String.Format(stEchoFmt,strFilePath));
//犯罪记录(“退出”);
//关闭流程
过程关闭();
//把单词读成字符串。
字符串结果=sOut.ReadToEnd().Trim();
//关闭io流;
sIn.Close();
sOut.Close();
我收到结果,但是,结果不完整,文件未提交或推入存储库

我得到的结果如下:

git status
git pull
git add "file.properties" "file.yaml" "file_metric.yaml"
git commit -m "Test Message"
git push
MicrosoftWindows[version6.3.9600](c)2013年微软公司。
版权所有。
folderPath\Test>git在分支主机上的状态您的分支是最新的
带有“源代码/主代码”。
要提交的更改:(使用“git reset HEAD…”取消Stage)
新文件:file.properties新文件:file.yaml新文件:
文件_metric.yaml
未提交的更改:(使用“git add…”更新
将提交的内容)(使用“git checkout…”放弃
工作目录中的更改)
修改:Git5.bat
未跟踪文件:(使用“git add…”包含在将要添加的内容中
(承诺的)
吉特·巴塔../TestGit·巴塔../TestGit·巴塔
folderPath\Test>git pull
已经更新了。
folderPath\Test>git add file.properties file.yaml file\u metric.yaml
folderPath\Test>git提交-m YAML文件
folderPath\Test>git推送
folderPath\Test>#folderPath\Test/Git_Bat.Bat成功运行。
退出
folderPath\Test>
可以看出,在执行Git.add Files命令后,我没有得到任何输出

当我尝试直接使用终端运行上面的批处理文件时,它成功运行,并且文件被正确推送


通过代码调用时是否需要进行任何更改?

我发现了我的错误,希望自己更正它

错误是在创建批处理文件时,文件名和注释没有用双引号括起来。其内容应如下:

git status
git pull
git add "file.properties" "file.yaml" "file_metric.yaml"
git commit -m "Test Message"
git push
希望这对其他人有帮助。 快乐编码:)