Browse Source

update RunCmd

Matthew R. Kasun 3 years ago
parent
commit
747baf1bba
2 changed files with 12 additions and 2 deletions
  1. 1 1
      netclient/daemon/freebsd.go
  2. 11 1
      netclient/ncutils/netclientutils_freebsd.go

+ 1 - 1
netclient/daemon/freebsd.go

@@ -103,7 +103,7 @@ netclient_args="daemon"`
 }
 
 func FreebsdDaemon(command string) {
-	out, err := ncutils.RunCmd("service netclient "+command, true)
+	out, err := ncutils.RunCmdFormatted("service netclient "+command, true)
 	ncutils.Log("output from RunCmd " + out)
 	ncutils.Log("error from RunCmd " + err.Error())
 }

+ 11 - 1
netclient/ncutils/netclientutils_freebsd.go

@@ -2,6 +2,7 @@ package ncutils
 
 import (
 	"context"
+	"fmt"
 	"log"
 	"os/exec"
 	"strings"
@@ -11,7 +12,16 @@ import (
 
 // RunCmdFormatted - run a command formatted for freebsd
 func RunCmdFormatted(command string, printerr bool) (string, error) {
-	return "", nil
+
+	args := strings.Fields(command)
+	cmd := exec.Command(args[0], args[1:]...)
+	cmd.Wait()
+	out, err := cmd.CombinedOutput()
+	if err != nil && printerr {
+		Log(fmt.Sprintf("error running command: %s", command))
+		Log(strings.TrimSuffix(string(out), "\n"))
+	}
+	return string(out), err
 }
 
 // GetEmbedded - if files required for freebsd, put here