summaryrefslogtreecommitdiff
path: root/shell.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-04 02:15:48 -0600
committerJeff Carr <[email protected]>2024-11-04 02:15:48 -0600
commitae5cadf5455d5f65fdab0b690b8d403090750fc3 (patch)
tree94c51d895fe61525f5a234d555c881ac0f204b76 /shell.go
parentf0b70125e84b3f998cbc68383678b0ae6e5b4261 (diff)
attempt stdout to httpv0.22.4
Signed-off-by: Jeff Carr <[email protected]>
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
+}