Skip to content

Comments

Inherit os.Stdin directly from the parent process#416

Open
myaaaaaaaaa wants to merge 1 commit intohomeport:mainfrom
myaaaaaaaaa:stdin
Open

Inherit os.Stdin directly from the parent process#416
myaaaaaaaaa wants to merge 1 commit intohomeport:mainfrom
myaaaaaaaaa:stdin

Conversation

@myaaaaaaaaa
Copy link

This fixes a bug where termshot command </dev/null (common in non-interactive environments such as CI) can result in the output of command being truncated.

This bug is due to a race condition where the instant EOF of /dev/null can cause defer func() { _ = pt.Close() }() to run before the output of command is finished writing. Since stdin, stdout, and stderr all refer to the same pty, this also closes stdout, which results in the rest of command's output being discarded.

Partially fixes #412

@myaaaaaaaaa
Copy link
Author

It's worth noting that the original version didn't even work in the first place - since both the child process and termshot itself were simultaneously reading from the same pseudo-terminal device, termshot can end up consuming the data meant for the child process. For example:

# Want
$ echo hi | sleep 0

# Got (before this PR is applied)
$ echo hi | termshot sleep 0
hi

# Got (after this PR is applied)
$ echo hi | termshot sleep 0

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

Successfully merging this pull request may close these issues.

Improve TTY handling / redraws

1 participant