title: How to write data to existing process's STDIN from external process?
body: <p>I'm seeking for ways to write data to the existing process's <code>STDIN</code> from external processes, and found similar question  <a href="https://stackoverflow.com/questions/3792054/how-do-you-stream-data-into-the-stdin-of-a-program-from-different-local-remote-pr">How do you stream data into the STDIN of a program from different local/remote processes in Python?</a> in stackoverlow.</p>
  
  <p>In that thread, @Michael says that we can get file descriptors of existing process in path like below, and permitted to write data into them on Linux.</p>
  
  <pre><code>/proc/$PID/fd/
  </code></pre>
  
  <p>So, I've created a simple script listed below to test writing data to the script's <code>STDIN</code> (and <code>TTY</code>) from external process.</p>
  
  <pre><code>#!/usr/bin/env python
  
  import os, sys
  
  def get_ttyname():
      for f in sys.stdin, sys.stdout, sys.stderr:
          if f.isatty():
              return os.ttyname(f.fileno())
      return None
  
  if __name__ == "__main__":
      print("Try commands below")
  
      print("$ echo 'foobar' &gt; {0}".format(get_ttyname()))
      print("$ echo 'foobar' &gt; /proc/{0}/fd/0".format(os.getpid()))
  
      print("read :: [" + sys.stdin.readline() + "]")
  </code></pre>
  
  <p>This test script shows paths of <code>STDIN</code> and <code>TTY</code> and then, wait for one to write it's <code>STDIN</code>.</p>
  
  <p>I launched this script and got messages below.</p>
  
  <pre><code>Try commands below
  $ echo 'foobar' &gt; /dev/pts/6
  $ echo 'foobar' &gt; /proc/3308/fd/0
  </code></pre>
  
  <p>So, I executed the command <code>echo 'foobar' &gt; /dev/pts/6</code> and <code>echo 'foobar' &gt; /proc/3308/fd/0</code> from other terminal. After execution of both commands, message <code>foobar</code> is displayed twice on the terminal the test script is running on, but that's all. The line <code>print("read :: [" + sys.stdin.readline() + "]")</code> was not executed.</p>
  
  <p>Are there any ways to write data from external processes to the existing process's <code>STDIN</code> (or other file descriptors), i.e. invoke execution of the line<code>print("read :: [" + sys.stdin.readline() + "]")</code> from other processes?</p>