(sample.go) : ./test.sh | ./sample
test
#!/bin/bash
echo $$
i=0
while [ $i -lt 50 ]
do
echo "$i time HELLO STDIN, $$!!!"
echo "$i time HELLO STDERR, $$!!!" >&2
sleep 1
i=`expr $i + 1`
done
-------------------------
sample.go
------------------------
package main
import (
"bufio"
"fmt"
"os"
"os/signal"
)
func main() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func(){
for sig := range c {
// sig is a ^C, handle it
fmt.Println(sig)
os.Exit(0)
}
}()
consolereader := bufio.NewReader(os.Stdin)
erreader := bufio.NewReader(os.Stderr)
for {
input, err := consolereader.ReadString('\n')
if err != nil {
fmt.Println(err)
os.Exit(1)
}
errinput, err1 := erreader.ReadString('\n')
if err1 != nil {
fmt.Println(err1)
os.Exit(1)
}
fmt.Println(input)
fmt.Println(errinput)
//fmt.Println(err)
}
fmt.Println("\"reader finished\"");
}
I expected output to be like this
0 time HELLO STDOUT, 1077!!!
0 time HELLO STDERR, 1077!!!
....
But i see only STDERR:
0 time HELLO STDERR, 1077!!!
1 time HELLO STDERR, 1077!!!
Any idea what i do wrong in my code? Are there any examples on this
particular task?
Thank you,
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.