Skip to content

Instantly share code, notes, and snippets.

@moutend
Created June 17, 2017 11:20
Show Gist options
  • Save moutend/c2bfdd03ee0f5897b0f2b9396b24abd0 to your computer and use it in GitHub Desktop.
Save moutend/c2bfdd03ee0f5897b0f2b9396b24abd0 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"log"
"os"
"os/exec"
)
func main() {
var err error
if err = run(os.Args); err != nil {
log.Fatal(err)
}
fmt.Println("done")
}
func run(args []string) (err error) {
var count int
var input string = args[1]
var output string
for {
count++
output = fmt.Sprintf("rec-%v-%v", count, input)
ctx, cancel := context.WithCancel(context.Background())
cmd1 := exec.CommandContext(ctx, "play", input)
cmd2 := exec.CommandContext(ctx, "rec", output)
go func() {
cmd1.Run()
cancel()
}()
go cmd2.Run()
_ = <-ctx.Done()
cmd3 := exec.Command("play", "-m", input, output)
cmd3.Run()
}
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment