Search code examples
bashshellipcstdinfile-descriptor

Write to stdin of process listening for messages


Say I start a process with:

#!/usr/bin/env bash

while read line; do
 echo "stdin message: $line"
done < "/dev/stdin"

apparently this process is listening for data being to written to its stdin. How can another process write to it?


Solution

  • It depends on what the process's stdin is connected to. If it's a named pipe, they write to the pipe file. If it's a pseudo-tty, they write to the corresponding master device.

    In most other cases, it's not generally possible.