Skip to content

Commit

Permalink
fix: Properly capture command stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
matbme committed Dec 17, 2023
1 parent 0df8137 commit 0fa973a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions core/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package albius

import (
"bytes"
"errors"
"fmt"
"os"
Expand All @@ -12,15 +13,15 @@ import (

// RunCommand executes a command in a subshell
func RunCommand(command string) error {
stderr := new(bytes.Buffer)

cmd := exec.Command("sh", "-c", command)
cmd.Stdout = os.Stdout
err := cmd.Run()
cmd.Stderr = stderr

err := cmd.Run()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
return errors.New(string(exitErr.Stderr))
}
return err
return errors.New(stderr.String())
}

return nil
Expand Down

0 comments on commit 0fa973a

Please sign in to comment.