Files
goffmpeg/pkg/cmd/exec.go
Fran ec40467798 cleanup & fix ci (#82)
* cleanup readme & examples
* upgrade go version
* add makefile with basic commands
* add e2e test
* add gha
* update .gitignore
2023-09-29 17:47:28 +02:00

36 lines
631 B
Go

package cmd
import (
"bytes"
"context"
"fmt"
"os/exec"
)
func FindBinPath(ctx context.Context, command string) (string, error) {
if command == "" {
return "", fmt.Errorf("command cannot be empty")
}
path, err := execBufferOutput(ctx, getFindCommand(), command)
if err != nil {
return "", err
}
return path, nil
}
func execBufferOutput(ctx context.Context, command string, args ...string) (string, error) {
var out bytes.Buffer
c := exec.CommandContext(ctx, command, args...)
c.Stdout = &out
err := c.Run()
if err != nil {
return "", fmt.Errorf("%s: %s", c.String(), err)
}
return out.String(), nil
}