Python background shell script communication
<p>I have 2 python scripts, <code>foo.py</code> and <code>bar.py</code>. I am running foo.py in the background using</p>

<pre><code>python foo.py &amp;
</code></pre>

<p>Now I want to run <code>bar.py</code> and use the stdout from this file to trigger script inside foo.py. Is this possible? I'm using Ubuntu 16.04 LTS.</p>

<p>You could use <a href="https://en.wikipedia.org/wiki/Named_pipe" rel="nofollow">UNIX named pipe</a> for that.</p>

<p>First, you create named pipe object by executing <code>mkfifo named_pipe</code> in the same directory, where you have your python files.</p>

<p>Your <code>foo.py</code> then could look like this:</p>

<pre><code>while True:
    for line in open('named_pipe'):
        print 'Got: [' + line.rstrip('\n') + ']'
</code></pre>

<p>And your <code>bar.py</code> could look like this:</p>

<pre><code>import sys

print &gt;&gt;open('named_pipe', 'wt'), sys.argv[-1]
</code></pre>

<p>So, you run your consumer process like this: <code>python foo.py &amp;</code>.
And finally, each time you execute <code>python bar.py Hello</code>, you will see the message <code>Got: [Hello]</code> in your console.</p>

<p>UPD: unlike Paul's answer, if you use <em>named</em> pipe, you don't have to start one of the processes from inside the other.</p>

python shell background-process