title: os.system() vs. os.popen() when using bash process substitution: ls: cannot access '/dev/fd/63': No such file or directory
body: <p>I'm trying to write a Python program that takes a file argument and sends it to a subprocess, using <code>os.popen()</code>. It works great for normal files. But it doesn't work when using bash Process Substitution (<a href="https://medium.com/factualopinions/process-substitution-in-bash-739096a2f66d" rel="nofollow noreferrer">short article</a>).</p>
  <p>Why does <code>os.system()</code> work but <code>os.popen()</code> fail for the same command (on Ubuntu)? Here is <code>run.py</code>:</p>
  <pre class="lang-py prettyprint-override"><code>#!/usr/bin/env python3
  import os
  import sys
  
  cmd = &quot;ls -l %s&quot; % sys.argv[1]
  os.system(cmd)
  pipe = os.popen(cmd)
  print(pipe.read(), end=&quot;&quot;)
  </code></pre>
  <p>Output:</p>
  <pre class="lang-sh prettyprint-override"><code># Both os.system(&quot;ls -l file&quot;) and os.popen(&quot;ls -l file&quot;) work great
  $ run.py file
  -rw-r--r-- 1 peter peter 313080 Apr 15 12:27 file
  -rw-r--r-- 1 peter peter 313080 Apr 15 12:27 file
  
  # os.system(&quot;ls -l /proc/self/fd/11&quot;) works great but os.popen(&quot;ls -l /proc/self/fd/11&quot;) fails
  $ run.py &lt;(cat file)
  lr-x------ 1 peter peter 64 Apr 15 12:27 /proc/self/fd/11 -&gt; 'pipe:[171197]'
  ls: cannot access '/proc/self/fd/11': No such file or directory
  </code></pre>
  <p>Does anybody know why <code>os.popen(&quot;ls -l /proc/self/fd/11&quot;)</code> fails like this?</p>
  <p>I've created a Perl version, <code>perl-run.pl</code>, to be a similar as I could muster to the Python <code>run.pl</code> version above, and both Perl's <code>system()</code> and <code>open()</code> work as I expect:</p>
  <pre class="lang-perl prettyprint-override"><code>#!/usr/bin/perl -w
  use strict;
  
  my $cmd = &quot;ls -l $ARGV[0]&quot;;
  system($cmd);
  open(my $i, $cmd . &quot; |&quot;);
  print &lt;$i&gt;;
  </code></pre>
  <p>Output:</p>
  <pre class="lang-sh prettyprint-override"><code>$ perl-run.pl &lt;(cat file) 
  lr-x------ 1 peter peter 64 Apr 15 12:27 /proc/self/fd/11 -&gt; 'pipe:[165704]'
  lr-x------ 1 peter peter 64 Apr 15 12:27 /proc/self/fd/11 -&gt; pipe:[165704]
  </code></pre>