从服务执行 git-bash.exe [英] Execute git-bash.exe from a service

查看:29
本文介绍了从服务执行 git-bash.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑在 Powershell 环境中自动部署代码.

I am looking at automating the deployment of the code in Powershell environments.

我可以在实际会话中轻松执行以下命令来更新存储库的代码:

I can easily execute the following command in a real session to get the code of a repository updated:

C:\path\to\PortableGit\git-bash.exe -c 'git -C  /c/path/to/repository.git pull' 

但是,我们不想登录会话来更新代码.

However we don't want to log into a session to update the code.

我们创建了一个负责更新存储库的服务.问题是该命令在真实会话中起作用,但在服务中不起作用 - 它只是挂断了.

We have created a Service that will be in charge of updating the repository. The issue is that this command works from a real session, but it does not work from a service - it just hangs up.

我相信是因为 git-bash.exe 需要在命令实际执行时用 bash 在短时间内打开一个新窗口.

I believe is because git-bash.exe requires to open a new Window with bash for a brief amount of time while the command is actually executed.

如何从服务执行此命令?还有其他合理的选择吗?

How can I execute this command from a Service ? Is there any other reasonable alternative ?

推荐答案

好吧,我终于看到除了使用 git.exe 而不是 bash-git 之外别无他法.

Well, finally I saw no other way than using the git.exe rather than bash-git.

因此,将命令转换为 Windows 本机就可以解决问题.如果你已经设置了私钥认证,你只需要设置HOMEPATH变量即可.

Therefore converting the command to the windows native will do the trick. If you have set up the private key authentication, you just need to set up the HOMEPATH variable.

$env:HOMEPATH="\Users\Administrator";C:\path\to\PortableGit\bin\git.exe -C C:\path\to\repository.git pull'

这篇关于从服务执行 git-bash.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆