[英]git-bash.exe: how to run single command?
I am using the portable version of Git for Windows , but when I use git-bash.exe
to run a single command, it looks like it does not work.我使用的是 Windows 版 Git的便携式版本,但是当我使用
git-bash.exe
运行单个命令时,它看起来不起作用。 Can you help me find out where is the problem?你能帮我找出问题出在哪里吗?
I have a PowerShell script to call below command.我有一个 PowerShell 脚本可以调用下面的命令。 But looks like it does not work.
但看起来它不起作用。 I am not able to let the new cmd window to pause to see the error log:
我无法让新的 cmd 窗口暂停以查看错误日志:
cmd /c "d:\git\git-bash.exe dos2unix d:\test\my-script.sh"
But If double click and run bash-exe.sh
, then in the git-bash.exe
window type但是如果双击并运行
bash-exe.sh
,则在git-bash.exe
窗口中键入
dos2unix d:\test\my-script.sh
then it works.那么它的工作原理。
There are a few different ways to call EXEs from PowerShell. 从PowerShell调用EXE有几种不同的方法。 One of the best ways I've found that allows you the most control is the Start-Process cmdlet.
我发现可以让您最大程度地控制自己的最佳方法之一是Start-Process cmdlet。 Instead of calling a cmd.exe window try this:
而不是调用cmd.exe窗口,请尝试以下操作:
Start-Process -FilePath 'd:\git\git-bash.exe' -ArgumentList 'dos2unix d:\test\my-script.sh'
Better yet convert that shell script into native PowerShell! 更好的是将该Shell脚本转换为本地PowerShell! :)
:)
Anyway, I got a walkaround. 无论如何,我有一个解决方案。 In the portable git, under \\usr\\bin, there is a exe called dos2unix.exe, so that I can directly call dos2unix.exe from my powershell scripts, not from git-bash.exe then call dos2unix command.
在可移植git的\\ usr \\ bin下,有一个名为dos2unix.exe的exe,因此我可以直接从Powershell脚本而不是git-bash.exe调用dos2unix.exe,然后再调用dos2unix命令。
cmd /c "d:\git\usr\bin\dos2unix.exe d:\test\my-script.sh"
With this walkaround, the problem resolved. 通过这种解决方法,问题得以解决。 But I still don't know why powershell calls dos2unix to parse my file does not work (I mean the file is not converted after call that command).
但是我仍然不知道为什么powershell调用dos2unix来解析我的文件不起作用(我的意思是在调用该命令后文件没有被转换)。
另一种解决方案是使用base.exe
,例如:
"%ProgramFiles%\Git\bin\bash.exe" start.sh
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.