summaryrefslogtreecommitdiff
path: root/shell.go
diff options
context:
space:
mode:
Diffstat (limited to 'shell.go')
-rw-r--r--shell.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/shell.go b/shell.go
index 4b309e0..9ef2dfb 100644
--- a/shell.go
+++ b/shell.go
@@ -2,6 +2,7 @@ package shell
import (
"io/ioutil"
+ "net/http"
"os"
"os/exec"
"strings"
@@ -176,3 +177,50 @@ func Cat(filename string) string {
}
return Chomp(buffer)
}
+
+/*
+// run interactively. output from the cmd is in real time
+// shows all the output. For example, 'ping -n localhost'
+// shows the output like you would expect to see
+func RunPathHttpOut(workingpath string, cmd []string, w http.ResponseWriter, r *http.Request) error {
+ log.Log(INFO, "NewRun() ", cmd)
+
+ process := exec.Command(cmd[0], cmd[1:len(cmd)]...)
+ // Set the working directory
+ process.Dir = workingpath
+ process.Stderr = os.Stderr
+ process.Stdin = os.Stdin
+ process.Stdout = os.Stdout
+ process.Start()
+ err := process.Wait()
+ log.Log(INFO, "shell.Exec() err =", err)
+ return err
+}
+*/
+
+func RunPathHttpOut(path string, cmd []string, w http.ResponseWriter, r *http.Request) error {
+ log.Warn("Run(): ", cmd)
+
+ process := exec.Command(cmd[0], cmd[1:len(cmd)]...)
+ process.Dir = path
+ process.Stderr = os.Stderr
+ process.Stdin = r.Body
+ process.Stdout = w
+ process.Start()
+ err := process.Wait()
+ log.Warn("shell.Exec() err =", err)
+ return err
+}
+
+func RunHttpOut(cmd []string, w http.ResponseWriter, r *http.Request) error {
+ log.Warn("NewRun() ", cmd)
+
+ process := exec.Command(cmd[0], cmd[1:len(cmd)]...)
+ process.Stderr = os.Stderr
+ process.Stdin = r.Body
+ process.Stdout = w
+ process.Start()
+ err := process.Wait()
+ log.Warn("shell.Exec() err =", err)
+ return err
+}