From a90739089110e9f92653792bb1f23888ad734a79 Mon Sep 17 00:00:00 2001 From: James Mills Date: Sun, 22 Mar 2020 18:01:27 +1000 Subject: Add support for transcoding --- utils/utils.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 utils/utils.go (limited to 'utils/utils.go') diff --git a/utils/utils.go b/utils/utils.go new file mode 100644 index 0000000..0ca1cea --- /dev/null +++ b/utils/utils.go @@ -0,0 +1,29 @@ +package utils + +import ( + "context" + "fmt" + "os/exec" + "time" +) + +// CmdExists ... +func CmdExists(cmd string) bool { + _, err := exec.LookPath(cmd) + return err == nil +} + +// RunCmd ... +func RunCmd(timeout int, command string, args ...string) error { + ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second) + defer cancel() + + cmd := exec.CommandContext(ctx, command, args...) + + out, err := cmd.CombinedOutput() + if err != nil { + return fmt.Errorf("cmd.CombinedOutput error: %w\n%s", err, out) + } + + return nil +} -- cgit v1.2.3