Browse Source

Pass stderr from command to local terminal

master v0.1.2
Trevor Slocum 2 years ago
parent
commit
466b499771
  1. 3
      CHANGELOG
  2. 15
      pkg/gate/portal.go

3
CHANGELOG

@ -1,3 +1,6 @@
0.1.2:
- Pass stderr from command to local terminal
0.1.1:
- Pass session environment variables to command

15
pkg/gate/portal.go

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

Loading…
Cancel
Save