如何使用GoLang以编程方式禁用Mac终端的回声

I am trying to disable echo from my Mac terminal using GoLang. I tried using

exec.Command("stty", "-F", "/dev/tty", "-echo").Run()

It works for linux terminal but it doesn't work for Mac and Windows. In Mac, in bash and zsh, I manually tried to use

stty -echo
stty -echoctl

Both didn't work.

Can anyone help with this?

Thanks!

While this doesn't directly answer the question of why your example does not work, here is how one could read the secret from a terminal without echoing it back (here is a link to the signature and documentation - link):

package main

import (
    "fmt"
    "syscall"

    "golang.org/x/crypto/ssh/terminal"
)

func main() {
    fmt.Println("Your password: ")
    bytepw, err := terminal.ReadPassword(int(syscall.Stdin))
    if err != nil {
        panic(err)
    }
    fmt.Println()
    fmt.Printf("Your password was '%s'
", string(bytepw))
}

Expected output:

mac:~ jabbson$ go run testpass.go
Your password:

Your password was 'mypass'
mac:~ jabbson$