correct argument passing

This commit is contained in:
Zhi Wang 2022-01-06 20:53:36 -05:00
parent 97791896e1
commit 3a87f6a58c

View File

@ -32,9 +32,9 @@ const (
closeGracePeriod = 10 * time.Second closeGracePeriod = 10 * time.Second
) )
func createPty(cmdline string) (*os.File, *exec.Cmd, error) { func createPty(cmdline []string) (*os.File, *exec.Cmd, error) {
// Create a shell command. // Create a shell command.
cmd := exec.Command(cmdline) cmd := exec.Command(cmdline[0], cmdline[1:]...)
// Start the command with a pty. // Start the command with a pty.
ptmx, err := pty.Start(cmd) ptmx, err := pty.Start(cmd)
@ -155,7 +155,7 @@ func fromPtyStdout(ws *websocket.Conn, ptmx *os.File, done chan struct{}) {
time.Sleep(closeGracePeriod) time.Sleep(closeGracePeriod)
} }
var cmdToExec string = "bash" var cmdToExec = []string{"bash"}
// handle websockets // handle websockets
func wsHandler(w http.ResponseWriter, r *http.Request) { func wsHandler(w http.ResponseWriter, r *http.Request) {
@ -244,7 +244,7 @@ func main() {
args := os.Args args := os.Args
if len(args) > 1 { if len(args) > 1 {
cmdToExec = strings.Join(args[1:], " ") cmdToExec = args[1:]
log.Println(cmdToExec) log.Println(cmdToExec)
} }