You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I encountered an issue when using the github.com/creack/pty library to create a pseudo-terminal. Below is the relevant code snippet:
cmd := exec.Command("/system/bin/sh")
// Allocate a pseudo-terminal for the subprocess
ptyMaster, err := pty.Start(cmd)
if err != nil {
return ErrPkg.NewErrD("Failed to start shell: " + err.Error())
}
When I send a command (e.g., ls followed by Enter) to the subprocess through the pseudo-terminal and then read the output, the output includes not only the command's execution result but also the command input itself. For example:
Input: ls
Output: ls\n + the actual command output
This behavior results in the output containing the input content, which is unexpected. I expect to receive only the command's execution result without the input echoed back.
Could you clarify if this behavior is intentional or if there's a way to avoid this echo in the output?
The text was updated successfully, but these errors were encountered:
This is indeed expected and has to do with the terminal, no directly the pty library.
If you take a look at the README, there is an example of a shell, the key part you are looking for is
// Set stdin in raw mode.oldState, err:=term.MakeRaw(int(os.Stdin.Fd()))
iferr!=nil {
panic(err)
}
deferfunc() { _=term.Restore(int(os.Stdin.Fd()), oldState) }() // Best effort.
That will pass through the terminal management to the underlying process.
If you only want to disable the output showing the input you can just disable ECHO and/or ICANON termios
I encountered an issue when using the github.com/creack/pty library to create a pseudo-terminal. Below is the relevant code snippet:
cmd := exec.Command("/system/bin/sh")
// Allocate a pseudo-terminal for the subprocess
ptyMaster, err := pty.Start(cmd)
if err != nil {
return ErrPkg.NewErrD("Failed to start shell: " + err.Error())
}
When I send a command (e.g., ls followed by Enter) to the subprocess through the pseudo-terminal and then read the output, the output includes not only the command's execution result but also the command input itself. For example:
This behavior results in the output containing the input content, which is unexpected. I expect to receive only the command's execution result without the input echoed back.
Could you clarify if this behavior is intentional or if there's a way to avoid this echo in the output?
The text was updated successfully, but these errors were encountered: