title: Why returncode=0 and no stdout for my subprocess.run?
body: <p>The simple python3 program named print-pid.py is running :</p>
  
  <pre><code>cat print-pid.py
  import os 
  from time import sleep  
  print('my pid is',os.getpid())
  sleep(1000)
  </code></pre>
  
  <p>The output for <code>python3 print-pid.py</code> is :</p>
  
  <pre><code>my pid is 5421
  </code></pre>
  
  <p>To get the pid with bash command.</p>
  
  <pre><code>ps aux|grep 'python3 print-pid.py'|grep -v grep |awk '{print $2}'
  5421
  </code></pre>
  
  <p>I wan to  get the pid of the program python3 print-pid.py when it is running with python's sbuprocess module.</p>
  
  <p>It is my try here:</p>
  
  <pre><code>import subprocess
  cmd = "ps aux|grep 'python3 print-pid.py'|grep -v grep |awk '{print $2}'"
  result = subprocess.run(cmd, stdout=subprocess.PIPE,shell=True)
  print(result)
  </code></pre>
  
  <p>The result confued me.</p>
  
  <p>CompletedProcess(args="ps aux|grep 'python3 print-pid.py'|grep -v grep |awk '{print $2}'", returncode=0, stdout=b''</p>
  
  <p>The <code>eturncode=0</code> means my bash command execute successfully,why <code>stdout=b''</code> instead of <code>stdout=b'5421'</code>?</p>
  
  <p>Thank for Allan's replace and test suggestion in the comment.</p>
  
  <p>For the bash command <code>ps aux|grep 'python3'</code> :</p>
  
  <pre><code>import subprocess
  cmd = "ps aux|grep 'python3'"
  result = subprocess.run(cmd, stdout=subprocess.PIPE,shell=True)
  print(result)
  </code></pre>
  
  <p>the output is:</p>
  
  <pre><code>CompletedProcess(args="ps aux|grep 'python3'", returncode=0,     
  stdout=b'debian9   6569  0.0  0.2  31916  9376 pts/0    S+   11:04   0:00 python3 print-p\ndebian9   6844  0.0  0.2  39860 11440 pts/2    S+   11:13   0:00 python3\ndebian9   6929  0.0  0.0  16980   948 pts/2    S+   11:17   0:00 grep python3\n') 
  </code></pre>
  
  <p>However for the bash command <code>ps aux|grep 'python3 print-pid.py'</code>:</p>
  
  <pre><code>import subprocess
  cmd = "ps aux|grep 'python3 print-pid.py'"
  result = subprocess.run(cmd, stdout=subprocess.PIPE,shell=True)
  print(result)
  </code></pre>
  
  <p>the output: </p>
  
  <pre><code>CompletedProcess(args="ps aux|grep 'python3 print-pid.py'", returncode=1, stdout=b'')
  </code></pre>
  
  <p>Why isn't it printing?</p>
  
  <pre><code>stdout=b'' instead of  stdout=b'debian9   6569  0.0  0.2  31916  9376 pts/0    S+   11:04   0:00 python3 print-p\n
  debian9   6929  0.0  0.0  16980   948 pts/2    S+   11:17   0:00 grep python3 print-pid.py\n'
  </code></pre>