Skip to content

fix: send command lines one per prompt in non-interactive mode - #37

Merged
kofrezo merged 1 commit into
masterfrom
dk_fix_stuck_prompt_on_sudo
Oct 9, 2026
Merged

kofrezo merged 1 commit into
masterfrom
dk_fix_stuck_prompt_on_sudo

Conversation

@kofrezo

@kofrezo kofrezo commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

--command and stdin mode queued the PS1 change, the command and the final exit in the pty all at once. The shell reads one line at a time, so the exit sat in the tty input queue while the command ran. Anything reading the tty swallowed it: sudo with use_pty relays all pending input to the pty it runs the command in, and a password prompt reads it as the password. Bash never got the exit and polysh waited forever, while a command like hostname -f that leaves the tty alone worked by luck.

Only replace the prompt up front and let its callback feed the next command line each time the shell asks for input, then exit once nothing is left, as the --prompt branch already does. PS2 gets the same trigger so that if/fi, heredocs and trailing backslashes ask for their next line the same way.

--command and stdin mode queued the PS1 change, the command and the final
exit in the pty all at once.  The shell reads one line at a time, so the
exit sat in the tty input queue while the command ran.  Anything reading
the tty swallowed it: sudo with use_pty relays all pending input to the
pty it runs the command in, and a password prompt reads it as the
password.  Bash never got the exit and polysh waited forever, while a
command like hostname -f that leaves the tty alone worked by luck.

Only replace the prompt up front and let its callback feed the next
command line each time the shell asks for input, then exit once nothing
is left, as the --prompt branch already does.  PS2 gets the same trigger
so that if/fi, heredocs and trailing backslashes ask for their next line
the same way.
@kofrezo
kofrezo requested a review from brainexe October 8, 2026 06:59
@kofrezo kofrezo self-assigned this Oct 8, 2026
@kofrezo kofrezo added the bug Something isn't working label Oct 8, 2026
@kofrezo

kofrezo commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Example where this was stuck before:

uv run polysh $HOSTS --command="sudo hostname -f"
xx7db.ds.ig.local  : xx7db.ds.ig.local
xx3db.ds.ig.local  : xx3db.ds.ig.local
xx6db.ds.ig.local  : xx6db.ds.ig.local
xx8db.ds.ig.local  : xx8db.ds.ig.local
xxp1db.ds.ig.local : xxp1db.ds.ig.local
xx4db.ds.ig.local  : xx4db.ds.ig.local
xx9db.ds.ig.local  : xx9db.ds.ig.local
xxs1db.ds.ig.local : xxs1db.ds.ig.local
xx2db.ds.ig.local  : xx2db.ds.ig.local
xx10db.ds.ig.local : xx10db.ds.ig.local
xx1db.ds.ig.local  : xx1db.ds.ig.local
xx5db.ds.ig.local  : xx5db.ds.ig.local
# <- Stuck forever

@brainexe brainexe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my test also worked 👍

@kofrezo
kofrezo merged commit f23bb7c into master Oct 9, 2026
8 checks passed
@kofrezo
kofrezo deleted the dk_fix_stuck_prompt_on_sudo branch October 9, 2026 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants