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 14:39:00 +02:00
|
|
|
package openwrt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os/exec"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CommandResult contain all information about a command execution, stdout, stderr
|
|
|
|
type CommandResult struct {
|
2018-09-19 15:22:51 +02:00
|
|
|
Stdout string
|
|
|
|
Stderr string
|
|
|
|
ReturnCode int
|
2018-09-19 14:39:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run executes a system command and returns
|
2018-09-19 15:22:51 +02:00
|
|
|
func run(command string, params ...string) *CommandResult {
|
2018-09-19 14:39:00 +02:00
|
|
|
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{
|
2018-09-19 15:22:51 +02:00
|
|
|
Stdout: out.String(),
|
|
|
|
Stderr: stderr.String(),
|
2018-09-19 14:39:00 +02:00
|
|
|
// FIXME
|
2018-09-19 15:22:51 +02:00
|
|
|
ReturnCode: 0,
|
2018-09-19 14:39:00 +02:00
|
|
|
}
|
|
|
|
}
|