Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture output for wish.Command #291

Open
robinovitch61 opened this issue Jun 30, 2024 · 2 comments
Open

Capture output for wish.Command #291

robinovitch61 opened this issue Jun 30, 2024 · 2 comments

Comments

@robinovitch61
Copy link

Describe the bug
For tea.ExecProcess, I've done something like this to capture output back to the application:

type StdoutProxy struct {
    SavedOutput []byte
}

func (so *StdoutProxy) Write(p []byte) (n int, err error) {
    so.SavedOutput = append(so.SavedOutput, p...)
    return os.Stdout.Write(p)
}

c := exec.Command("bash")
stdoutProxy := &StdoutProxy{}
c.Stdout = stdoutProxy
tea.ExecProcess(c, func(err error) tea.Msg {
    return ExecCompleteMsg{Output: string(stdoutProxy.SavedOutput)}
}

Which has worked nicely. But when I do something similar with a wish.Command and tea.Exec, it doesn't work:

wc := wish.Command(session, "bash")
wc.SetStdout(stdoutProxy)
tea.Exec(wc, func(err error) tea.Msg {
    return ExecCompleteMsg{Output: string(stdoutProxy.SavedOutput)}
}

In this second case, SavedOutput is empty. Any tips here?

Setup
Please complete the following information along with version numbers, if applicable.

  • OS macOS
  • Shell zsh
  • Terminal Emulator iterm2
  • Terminal Multiplexer tmux

Note: you might encounter rendering issues if your locale does not use
UTF-8 encoding. Please check your locale (locale on POSIX systems) to
see what encoding is being used by your system.

❯ locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL=

Expected behavior
SavedOutput is not empty in the second case.

@caarlos0
Copy link
Member

caarlos0 commented Jul 1, 2024

because of this:

wish/cmd.go

Lines 64 to 71 in 939d28f

// SetStderr conforms with tea.ExecCommand.
func (*Cmd) SetStderr(io.Writer) {}
// SetStdin conforms with tea.ExecCommand.
func (*Cmd) SetStdin(io.Reader) {}
// SetStdout conforms with tea.ExecCommand.
func (*Cmd) SetStdout(io.Writer) {}

in any case, setting the output to stdout would not work, it needs to be the ssh session.

don't quite remember why we don't allow to set the cmd out and etc

@caarlos0
Copy link
Member

caarlos0 commented Jul 1, 2024

ahh, just remembered why.

because it might run on a pty, in which case it'll be overridden by the slave IO anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants