I am trying to create a subprocess from Golang. The goal is to read and process input in turn. Here is what I am trying to get:
func readStuff(scanner *bufio.Scanner) { for scanner.Scan() { fmt.Println("Performed Scan") fmt.Println(scanner.Text()) } if err := scanner.Err(); err != nil { fmt.Fprintln(os.Stderr, "reading standard input:", err) } } func main() { cmd := exec.Command("/usr/local/bin/pocketsphinx_continuous", "-inmic", "yes") out, err := cmd.StdoutPipe() err = cmd.Start() checkError(err) scanner := bufio.NewScanner(out) fmt.Println("Scanner created") defer cmd.Wait() go readStuff(scanner) }
In this example, "Created Scanner" is printed, but nothing happens after that.
Running this command, however, leads to what I expect to print:
/usr/local/bin/pocketsphinx_continuous -inmic yes 1>out.txt
And also changing the code for direct copying to stdout also works:
cmd := exec.Command("/usr/local/bin/pocketsphinx_continuous", "-inmic", "yes") cmd.Stdout = os.Stdout
What am I missing, what prevents me from reading the result?
go
tgrosinger
source share