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

Issue with Shell Example #17

Open
mvastola opened this issue Dec 27, 2023 · 0 comments
Open

Issue with Shell Example #17

mvastola opened this issue Dec 27, 2023 · 0 comments

Comments

@mvastola
Copy link

Hey, so I came across this and it looks like a really cool library (thanks for making it!), and I was hoping to use it in a project I'm working on.

Basically, what I'm trying to implement is very similar to your shell example, except that the example isn't behaving the way I expected it to. Essentially, I'm looking to use this package from a background service on my system, and have that background service spawn a pty that a user can connect to and use normally by running screen /dev/ttys002 or similar.

When I run the shell example though, it seems to effectively run it in my current TTY, which is obviously not too helpful in my case. It seems this might be intended given the code, particularly with regard to the io.Copy routines reading/writing os.Stdout/os.Stdin, as well as the fact ptmx.Name() isn't outputted at all.

// Set stdin in raw mode.
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
if err != nil {
panic(err)
}
defer func() { _ = term.Restore(int(os.Stdin.Fd()), oldState) }() // Best effort.
// Copy stdin to the pty and the pty to stdout.
// NOTE: The goroutine will keep reading until the next keystroke before returning.
go io.Copy(ptmx, os.Stdin)
go io.Copy(os.Stdout, ptmx)

I tried to play with the arguments to the IO functions and replace os.Std* with a handle to ptmx.Name(), and that got the shell to seem to not use the current TTY, but I still can't seem to do anything at all inside the screen connected to ptmx.Name(). No data echos no matter what I type (stty shows echo enabled though), and typing exit doesn't seem to reach bash because it doesn't exit.

I feel like I can't be far off at all from getting this to work, but I can't figure out what I'm missing. I'm also confused as to how the shell example was supposed to work in the first place. If you could point me in the right direction I'd really appreciate it.

Thanks so much

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

1 participant