Skip to content

Instantly share code, notes, and snippets.

@Cubixmeister
Created April 16, 2016 00:15
Show Gist options
  • Save Cubixmeister/40abc0b6fe6693a7d78373f032c01e56 to your computer and use it in GitHub Desktop.
Save Cubixmeister/40abc0b6fe6693a7d78373f032c01e56 to your computer and use it in GitHub Desktop.
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