I want to realize the pause function like windows shell command pause. For example,
$ go run script.go
Any key to continue... //Then any key to continue
On windows, we can use the system command by golang function exec.Command(). But how about on Linux? I want to use the command read -n1 -p "Any key to continue" as a compromised one, but it doesn't work in the function exec.Command("read", "-n", "1"). I tested a lot but failed to know why.
Besides, do anyone know how to achieve the pause function just by golang language itself without using the external command?
Just read from stdin. The user would have to press enter for you program to continue. Or set the terminal into "raw" mode. For the later case, there's eg. nsf's termbox
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With