如何退出 ASP.NET 页面并执行 git 命令?
我希望我的 ASP.NET 页面能够 shell 并执行 git 命令。我将命令放入有效的 bat 文件中:
REM cd to the git repo folder
cd c:\temp\mygitrepo
"c:\Program Files\Git\Bin\git.exe" show c090dc4b8b1b3512c1b5363c371e21d810d02f54 -- myfile.txt
如果我从 cmd 提示符运行我的 .bat 文件,没有问题。 如果我使用 System.Diagnostics.Process.Start 运行它,则会收到此错误:
已请求 RUNTIME_PREFIX,但前缀计算失败。使用静态回退
错误来自此 git 文件:http://github。 com/git/git/blob/master/exec_cmd.c
我使用完全相同的技术来运行 svn.exe 命令,没问题。
编辑 1:从此处的帖子我了解到msysgit 在与当前用户(我)而不是所有用户关联的位置安装一些文件。 IIS Web 服务器正在另一个用户帐户下运行。我尝试将一些引起我注意的 git 文件(例如 .gitconfig)复制给其他用户(在“文档和设置”中)。运气不好。因此,我将注意力转移到让 IIS 在启动 git 命令时模拟我。
I want my ASP.NET page to shell out and execute git commands. I put the commands in a bat file which works:
REM cd to the git repo folder
cd c:\temp\mygitrepo
"c:\Program Files\Git\Bin\git.exe" show c090dc4b8b1b3512c1b5363c371e21d810d02f54 -- myfile.txt
If I run my .bat file from a cmd prompt, no problem.
If I run it using System.Diagnostics.Process.Start, I get this error:
RUNTIME_PREFIX requested, but prefix computation failed. Using static fallback
The error is coming from this git file: http://github.com/git/git/blob/master/exec_cmd.c
I use exactly the same technique to run svn.exe commands, no problem.
EDIT 1: From the thread here I've learned that msysgit installs some files in a location associated with the current user, me, instead of all users. The IIS web server is running under another user account. I tried copying some of the git files that caught my eye, like .gitconfig, to other users (in Documents and Settings). No luck. So, I have switched my focus to getting IIS to impersonate me when it launches the git command.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这实际上是一个错误,还是只是通知您回退?根据链接的代码,该命令似乎仍应成功执行,仅使用静态前缀而不是 RUNTIME_PREFIX。
如果命令确实失败,您可能需要确保从 .NET 启动进程时所有必需的环境变量都可用。您可能还需要模拟不同的 Windows 标识才能以适当的权限运行命令(我假设 ASP.NET 标识受到尽可能的限制。) ProcessStartInfo 对象提供了几种配置进程的方法,包括 Windows身份、过程动词和环境变量。确保在运行批处理文件之前提供所需的正确上下文。
Is it actually an error, or is it just notifying you of a fallback? Based on the code linked, it appears that the command should still execute successfully, only using the static PREFIX rather than the RUNTIME_PREFIX.
If the command is indeed failing, you might want to make sure that any required environment variables are available when starting the process from .NET. You might also need to impersonate a different windows identity to run the command with proper permissions (I am assuming that the ASP.NET identity is restricted as much as possible.) The ProcessStartInfo object provides a few ways to configure the process, including the windows identity, the process verb, and environment variables. Make sure you are providing the proper context that your batch file requires before running it.