Commit 466b4997 authored by Trevor Slocum's avatar Trevor Slocum

Pass stderr from command to local terminal

parent b3960a5b
Pipeline #111889243 passed with stage
in 49 seconds
0.1.2:
- Pass stderr from command to local terminal
0.1.1:
- Pass session environment variables to command
......
......@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"log"
"os"
"os/exec"
"path"
......@@ -59,18 +60,25 @@ func NewPortal(name string, address string, command []string) (*Portal, error) {
if len(command) > 1 {
args = command[1:]
}
cmd := exec.CommandContext(cmdCtx, command[0], args...)
cmd.Env = append(sshSession.Environ(), fmt.Sprintf("TERM=%s", ptyReq.Term))
stderr, err := cmd.StderrPipe()
if err != nil {
log.Printf("error: failed to create stderr pipe for portal %s: %s", name, err)
return
}
go func() {
io.Copy(sshSession.Stderr(), stderr)
}()
f, err := pty.Start(cmd)
if err != nil {
io.WriteString(sshSession, fmt.Sprintf("failed to start command: failed to initialize pseudo-terminal: %s\n", err))
sshSession.Exit(1)
return
}
defer f.Close()
go func() {
for win := range winCh {
setWinsize(f, win.Width, win.Height)
......@@ -82,6 +90,7 @@ func NewPortal(name string, address string, command []string) (*Portal, error) {
}()
io.Copy(sshSession, f)
f.Close()
cmd.Wait()
},
PtyCallback: func(ctx ssh.Context, pty ssh.Pty) bool {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment