-5

I have an application that accepts input from stdin, let's call this application suman-f which can be run via the command line. I'd like to limit the input to the real human user only and not allow input from automated programs. The reason for this is because if multiple processes are sending information to stdin, it will get garbled, as there is only one information channel but multiple communicators.

Is there a way to prevent anything but a human executing suman-f via a terminal?

Or if there is some magical way to multiplex stdin, I'd love to hear about it.

1 Answers1

1

Short answer is no.

Unix system has no way to know if stdin of a particular process is handled by a human.

tty

your best approximation is tty. (see man tty).

tty (terminal) are the way to interact with system ( see What is the exact difference between a 'terminal', a 'shell', a 'tty' and a 'console'? ).

This is how it works

if tty -s
then
    echo a human might be reading "or not)"
else
    echo output is a file
fi

in other word

  • if tty -s return false, you know output is a file (not a user),
  • if tty -s return true, you don't know.

This allow different formating (like ls), or prevent from interactive usage.

Archemar
  • 31,554