Created
June 17, 2017 11:20
-
-
Save moutend/c2bfdd03ee0f5897b0f2b9396b24abd0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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