attempt stdout to http

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-11-04 02:15:48 -06:00
parent f0b70125e8
commit ae5cadf545
1 changed files with 48 additions and 0 deletions

View File

@ -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
}