diff options
| author | James Mills <prologic@shortcircuit.net.au> | 2020-03-22 18:01:27 +1000 |
|---|---|---|
| committer | James Mills <prologic@shortcircuit.net.au> | 2020-03-22 18:01:27 +1000 |
| commit | a90739089110e9f92653792bb1f23888ad734a79 (patch) | |
| tree | cf7b364140e560d4e062607e1ec71567cf843360 /utils/utils.go | |
| parent | ce3008222e924902352d697b45626aebd8980af1 (diff) | |
Add support for transcoding
Diffstat (limited to 'utils/utils.go')
| -rw-r--r-- | utils/utils.go | 29 |
1 files changed, 29 insertions, 0 deletions
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 +} |
