This repository has been archived on 2024-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
2018-09-19 15:22:51 +02:00
|
|
|
package openwrt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os/exec"
|
|
|
|
)
|
|
|
|
|
2018-09-20 10:59:11 +02:00
|
|
|
// Executor interface to describe command runners signature
|
2018-09-19 15:22:51 +02:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|