2

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. Can you help me find out where is the problem?

I have a PowerShell script to call below command. 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 /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

dos2unix d:\test\my-script.sh

then it works.

4
  • I don't know how git-bash.exe works, but try adding a -c: cmd /c "d:\git\git-bash.exe -c dos2unix d:\test\my-script.sh" Commented Sep 28, 2015 at 20:59
  • How exactly does it "not work"? What behavior do you expect, and how does that differ from the behavior you actually get? Commented Sep 28, 2015 at 21:40
  • Can you try running that same command from, say, a command prompt? Then you can see any errors that may result... Commented Sep 28, 2015 at 21:55
  • @mah You need to quote the argument to -c too. I don't know how you nest quotes in CMD; try doubling the inner ones? But also, the cmd wrapper seems useless here. bash -c "dos2unix filename" Commented Dec 3, 2024 at 7:06

4 Answers 4

2

There are a few different ways to call EXEs from PowerShell. One of the best ways I've found that allows you the most control is the Start-Process cmdlet. Instead of calling a cmd.exe window try this:

Start-Process -FilePath 'd:\git\git-bash.exe' -ArgumentList 'dos2unix d:\test\my-script.sh'

Better yet convert that shell script into native PowerShell! :)

Sign up to request clarification or add additional context in comments.

Comments

1

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.

 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).

1 Comment

This worked for me after I changed the path to the script file to Linux-style (/d/test/my-script.sh). With the Windows-style path I get dos2unix: Failed to open temporary output file: No such file or directory...
0

In case you want to run the command and get the stdout, instead of opening another terminal window you can use this:

gitbash --login -c "dos2unix d:\test\my-script.sh"

Where gitbash is a symlink to C:\Program Files\Git\bin\bash.exe and is in $Env:Path on the Windows side. Optionally, --login is used for loading the profile.

So many problems just because Microsoft decided to put a space into Program Files

1 Comment

The --login option seems to serve no useful purpose here.
-1

Another solution is use the base.exe, e.g:

"%ProgramFiles%\Git\bin\bash.exe" start.sh

1 Comment

This runs a script. The OP specified that he wants to run a command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.