Piping data to Linux program which expects a TTY (terminal) Piping data to Linux program which expects a TTY (terminal) linux linux

Piping data to Linux program which expects a TTY (terminal)


unbuffer, part of expect (sudo apt-get install expect-dev on Ubuntu Lucid), can fool a program into thinking it's connected to a TTY.

$ tty /dev/pts/3$ echo | tty not a tty$ echo | unbuffer tty /dev/pts/11


You can use socat for this: echo your stdin strings | socat EXEC:"your_program",pty STDIO >/stdout_file

For example with bash: echo ls | socat EXEC:'bash',pty STDIO >/tmp/ls_out

Or as described here, for a program run with docker:

# Run the docker task, here bash, in backgrounddocker run -it --rm --name test ubuntu &# Send "ls -la" to the bash running inside dockerecho 'ls -la' | socat EXEC:'docker attach test',pty STDIN# Show the resultdocker logs test