Skip to content

Ctrl-c can't close read with tty & pipe #1826

Closed

Description

@leeola

The following command fails to exit on Ctrl-C

echo "read foo < /dev/tty" | fish

Is this a bug? or is there a workaround for this?

(Note: This is just an example to show piping into fish. Assume that the code is being piped in from cURL, or something similar, into fish.)

Activity

  1. geoff-nixon commented on Nov 25, 2014

    @geoff-nixon
    Contributor

    No, its not a bug. Ctrl-C is a terminal escape sequence which is (usually) mapped to the special non-printable 'intr' character, represented by the sequence ^C when non-printing characters are force-printed. [See man cat, option -v.] This character typically is used by the shell to send a SIGINT signal. But still, this is a character like any other.

    The command you're piping to fish, read foo < /dev/tty, explicitly tells the shell to redirect everything printed to your terminal device to read, and this includes non-printable characters. So when you press Ctrl-C, this character is sent to read just like any other. The read command "reads" a single line— that is, it continues until it encounters either the EOL character (return), or the EOF character, which can be sent with the escape sequence Ctrl-D.

  2. ridiculousfish commented on Nov 25, 2014

    @ridiculousfish
    Member

    I have to confess I don't understand what's going on. The INTR character does appear on the fd when this redirection is set up, but only if ISIG is unset in the termios. If ISIG is set, which it is by default, it just seems to cancel the current line (i.e. ICANON). It doesn't appear that the signal is being blocked by signal_block(), and it doesn't appear to be delivered to fish. So it's probably being delivered to another signal handler (or otherwise blocked). I need to investigate more.

  3. leeola commented on Nov 25, 2014

    @leeola
    Author

    @geoff-codes Thanks for the explanation.

    Is there a better way to get user input through a piped stdin then? Perhaps i'm not using the right tool for my application. By better, i mean a consistent UX with read foo where Ctrl-C interrupts the read process.

  4. added this to the fish-future milestone on Feb 3, 2015
  5. krader1961 commented on Mar 23, 2017

    @krader1961
    Contributor

    This has been fixed in the interim since it was opened.

  6. zanchey commented on May 17, 2017

    @zanchey
    Member

    Well, it dies with an error message:

    > echo "read foo < /dev/tty" | fish
    <W> fish: No TTY for interactive shell (tcgetpgrp failed)
    setpgid: Inappropriate ioctl for device
    

    Is that the right behaviour here? I think so...

  7. locked as resolved and limited conversation to collaborators on Apr 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions