diff options
| author | Jeff Carr <[email protected]> | 2024-11-04 02:15:48 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-04 02:15:48 -0600 |
| commit | ae5cadf5455d5f65fdab0b690b8d403090750fc3 (patch) | |
| tree | 94c51d895fe61525f5a234d555c881ac0f204b76 | |
| parent | f0b70125e84b3f998cbc68383678b0ae6e5b4261 (diff) | |
attempt stdout to httpv0.22.4
Signed-off-by: Jeff Carr <[email protected]>
| -rw-r--r-- | shell.go | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -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 +} |
