Added edgeapps package, cleaned up redundancies

This commit is contained in:
Paulo Truta
2021-02-15 20:37:16 +01:00
parent 9f20211bf4
commit ad28e1a505
8 changed files with 111 additions and 41 deletions
+3
View File
@@ -0,0 +1,3 @@
module github.com/edgebox-iot/sysctl/internal/utils
go 1.15
+24
View File
@@ -0,0 +1,24 @@
package utils
import (
"bytes"
"fmt"
"log"
"os/exec"
)
// Exec : Runs a terminal Command, catches and logs errors, returns the result.
func Exec(command string, args []string) string {
cmd := exec.Command(command, args...)
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
log.Println(fmt.Sprint(err) + ": " + stderr.String())
}
log.Println("Result: " + out.String())
return out.String()
}