title: Assign shell script output to python variable ignoring error messages
body: <p>I have a python script that I am using to call a bash script that renames a file.  I then need the new name of the file so python can do some further processing on it.  I'm using subprocess.Popen to call the shell script.  The shell script echos the new file name so I can use stdout=subprocess.PIPE to get the new file name.</p>
  
  <p>The problem is that sometimes the bash script tries to rename the file with it's old name depending on the circumstances and so gives the message that the two files are the same from the mv command.  I have cutout all the other stuff and included a basic example below.</p>
  
  <pre><code>$ ls -1
  test.sh
  test.txt
  </code></pre>
  
  <p>This shell script is just an example to force the error message.</p>
  
  <pre><code>$ cat test.sh
  #!/bin/bash
  mv "test.txt" "test.txt"
  echo "test"
  </code></pre>
  
  <p>In python:</p>
  
  <pre><code>$ python
  &gt;&gt;&gt; import subprocess
  &gt;&gt;&gt; p = subprocess.Popen(['/bin/bash', '-c', './test.sh'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  &gt;&gt;&gt; p.stdout.read()
  "mv: `test.txt' and `test.txt' are the same file\ntest\n"
  </code></pre>
  
  <p>How can I ignore the message from the mv command and only get the output of the echo command?  If all goes well the only output of the shell script would be the result of the echo so really I just need to ignore the mv error message.</p>
  
  <p>Thanks,</p>
  
  <p>Geraint</p>