38 lines
606 B
Go
38 lines
606 B
Go
package openwrt
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"log"
|
|
"os/exec"
|
|
)
|
|
|
|
type Executor interface {
|
|
Run(command string, params ...string) *CommandResult
|
|
}
|
|
|
|
type localExecutor struct{}
|
|
|
|
func (e *localExecutor) 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,
|
|
}
|
|
}
|