title: How to pass error message from shell script to Python script?
body: <p>I am calling shell script from Python script using subprocess module. In my below python code, <code>shell_script</code> is my actual script.</p>
  
  <pre><code>proc = subprocess.Popen(shell_script, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, executable='/bin/bash')
  (stdout, stderr) = proc.communicate()
  if proc.returncode != 0:
      print("Errors while executing the shell script: %s" % stderr)
      break
  </code></pre>
  
  <p>And here is my shell script which is failing for sure as I am deliberately making it fail and then I am echoing out this <code>echo "Folder doesn't exist on $machine";</code> error on the shell script and then exiting with status 1. </p>
  
  <p>But this error message doesn't get showed up on the Python script side as I am printing it out using <code>stderr</code> if you see my above python code.</p>
  
  <pre><code>for machine in "${MACHINES[@]}"; do
     dircheck=($(ssh -o "StrictHostKeyChecking no" david@${machine} [[ ! -d "$dir3" ]] \&amp;\&amp; exit 1 \; ls -t1 "$dir3"))
  
     if [[ $? != 0 ]] ;then
         echo "Folder doesn't exist on $machine";
         exit 1
     fi
  
     if [[ "${dircheck[@]}" = '' ]] ;then
         echo "0 Files on server $machine in $dir3";
         exit 1
     fi
  done
  </code></pre>
  
  <p>Any idea what's wrong and what should I do? I am just trying to reflect error message whatever is happening on the shell script to the Python script whenever there is any error.</p>