// begin code
package main
import "fmt"
import "os/exec"
import "log"
import "runtime"
var done = make(chan error)
func watch() {
for {
select {
case err := <-done:
log.Printf("process done with error = %v", err)
}
}
}
func main() {
go watch()
var err error
fmt.Println("Hello, playground")
app1 := exec.Command("arecord")
app2 := exec.Command("aplay")
if app2.Stdin, err = app1.StdoutPipe(); err != nil {
log.Fatal(err)
}
if err := app1.Start(); err != nil {
log.Fatal(err)
}
if err = app2.Start(); err != nil {
log.Fatal(err)
}
go func() {
done <- app1.Wait()
}()
go func() {
done <- app2.Wait()
}()
for{runtime.Gosched()}
}
//end code
When you execute in a shell `arecord|aplay`, you can killall aplay and arecord will exit OR you can killall arecord and aplay will exit.
I try to do the same thing in this example.
If I killall arecord, aplay will exit. Good
If I killall aplay, arecord stays there, and aplay exits. Not good.
Any idea ?
Thanks !