git-bash.exe中的进程无法打开"CONIN$"



当我在git-bash.exe中启动一个cli.exe,它试图在Windows上打开进程的终端(打开文件CONIN$(时,它不起作用:(Go中的此处(

// GetCtty gets the file descriptor of the controlling terminal.
// Taken from:
// https://github.com/mattn/go-tty/blob/master/tty_windows.go
func GetCtty() (*os.File, error) {
in, err := syscall.Open("CONIN$", syscall.O_RDWR, 0)
if err != nil {
return nil, err
}
return os.NewFile(uintptr(in), "/dev/tty"), nil
}

GetCtty()返回一个错误,意味着没有这样的东西?为什么?在所有其他可用的实例中,WSL bash(execute.exe(、Powershell、Cmd、VS Code Integrated Terminal with(bash.exe from git for windows…(

我无法重现这个。使用此程序:

package main
import (
"fmt"
"syscall"
)
func main() {
_, err := syscall.Open("CONIN$", syscall.O_RDWR, 0)
fmt.Println(err)
}

只需PowerShell,我就可以得到:

PS C:> .open.exe
<nil>

然后用MSYS2 Bash,我得到了这个:

PS C:> bash.exe
bash-5.1$ ./open.exe
<nil>

就个人而言,如果Windows将成为您的";日常驾驶员";,我建议不要使用git-bash.exe或WSL。Go不像C,在构建过程中有所有这些支持Makefile和Shell脚本。在大多数情况下,你只需要编写Go代码,然后使用Go编译器进行编译。所以我发现Bash实际上不需要参与这个过程,我现在只使用PowerShell。如果你真的因为其他原因需要Bash,你可以安装MSYS2 Bash软件包:

https://packages.msys2.org/package/bash

最新更新