Created
April 16, 2016 00:15
-
-
Save Cubixmeister/40abc0b6fe6693a7d78373f032c01e56 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
"io" | |
"syscall" | |
"time" | |
"bytes" | |
) | |
func main() { | |
fd2, err := syscall.Dup(int(os.Stdin.Fd())) | |
if err != nil { | |
panic(err) | |
} | |
stdin2 := os.NewFile(uintptr(fd2), "stdin2") | |
go io.Copy(os.Stdout, stdin2) | |
time.Sleep(5 * time.Second) | |
stdin2.Close() | |
os.Stdout.WriteString("\n--- stdin2 closed ---\n") | |
var buf = make([]byte, 128) | |
for { | |
n, _ := os.Stdin.Read(buf) | |
os.Stdout.Write( bytes.ToUpper(buf[:n]) ) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment