I’m using
/dev/tty
/dev/tty
Example program
To clarify the issue, here is a simple demo program, written in Go:
package main import ( "fmt" "io" "os" ) func main() { fmt.Println("Received via standard input:") io.Copy(os.Stdout, os.Stdin) tty, err := os.Open("/dev/tty") if err != nil { panic(err) } defer tty.Close() var interactiveInput string fmt.Print("Enter some intput interactively: ") fmt.Fscanln(tty, &interactiveInput) fmt.Println("Received interactively:", interactiveInput) }On a UNIXy system I get this behaviour:
$ echo foo | ./tty_demo Received via standard input: foo Enter some intput interactively: bar Received interactively: barOn Windows I get this behaviour:
> echo foo | tty_demo.exe Received via standard input: foo panic: open /dev/tty: The system cannot find the path specified. goroutine 1 [running]: main.main() /tmp/tty_demo.go:15 +0x305
Anonymous Asked question May 13, 2021
Recent Comments