skratchdot / open-golang

Open a file, directory, or URI using the OS's default application for that object type. Optionally, you can specify an application to use.
MIT License
783 stars 65 forks source link

Run() fails on Windows in Git Bash / Cygwin / MSYS environments #34

Open watsonian opened 1 year ago

watsonian commented 1 year ago

We have a CLI tool that runs code like this:

if err := open.Run(url); err != nil {
  utils.Log("Unable to launch a browser")
  utils.LogDebugError(err)
}

It works fine in Linux, MacOS and in a Windows command prompt. However, it fails when it executes inside Git Bash (which is essentially a MSYS/Cygwin-like environment). The failure message is "Incorrect function".

My suspicion here is that the Windows implementation simply doesn't work in MSYS/Cygwin-style environments. Simply running start $URL in Git Bash opened up a browser as expected. Also, prefixing the command with winpty worked (which is included with Git Bash by default – see https://github.com/rprichard/winpty).