mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 08:55:24 +00:00
23 lines
489 B
Go
23 lines
489 B
Go
//go:build !windows
|
|
|
|
package scripts
|
|
|
|
import (
|
|
"context"
|
|
"os/exec"
|
|
"path/filepath"
|
|
)
|
|
|
|
func execCmd(ctx context.Context, scriptPath string) (output []byte, exitCode int, err error) {
|
|
// initialize to -1 in case the process never starts
|
|
exitCode = -1
|
|
|
|
cmd := exec.CommandContext(ctx, "/bin/sh", scriptPath)
|
|
cmd.Dir = filepath.Dir(scriptPath)
|
|
output, err = cmd.CombinedOutput()
|
|
if cmd.ProcessState != nil {
|
|
exitCode = cmd.ProcessState.ExitCode()
|
|
}
|
|
return output, exitCode, err
|
|
}
|