39 lines
687 B
Go
39 lines
687 B
Go
|
package openwrt
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"fmt"
|
||
|
"log"
|
||
|
"os/exec"
|
||
|
)
|
||
|
|
||
|
// CommandResult contain all information about a command execution, stdout, stderr
|
||
|
type CommandResult struct {
|
||
|
stdout string
|
||
|
stderr string
|
||
|
returnCode int
|
||
|
}
|
||
|
|
||
|
// Run executes a system command and returns
|
||
|
func Run(command string, params ...string) *CommandResult {
|
||
|
var out bytes.Buffer
|
||
|
var stderr bytes.Buffer
|
||
|
|
||
|
exe := exec.Command(command, params...)
|
||
|
exe.Stdout = &out
|
||
|
exe.Stderr = &stderr
|
||
|
|
||
|
err := exe.Run()
|
||
|
if err != nil {
|
||
|
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
|
||
|
return &CommandResult{
|
||
|
stdout: out.String(),
|
||
|
stderr: stderr.String(),
|
||
|
// FIXME
|
||
|
returnCode: 0,
|
||
|
}
|
||
|
}
|