title: Python: How to use backticks in subprocess?
body: <p>I would like to run a subprocess from Python. Inside the command string are several subcommands with backticks:</p>
  
  <pre><code>subprocess = subprocess.Popen(["echo", "COMMAND [`date +%%s`] SCHEDULE_HOST_DOWNTIME;%s;`date +%%s`;`date -d 'now + %d sec' +%%s`;1;;;%s;Downtime comment" % (hostname, 300, username)], stdout=subprocess.PIPE)
  </code></pre>
  
  <p>Though the <code>date</code> commands in the backticks are not executed. The stdout of this command is:</p>
  
  <pre><code>COMMAND [`date +%s`] SCHEDULE_HOST_DOWNTIME;example.com;`date +%s`;`date -d 'now + 300 sec' +%s`;1;;;my-username;Downtime comment
  </code></pre>
  
  <p>I also tried to use <code>$(date +%s)</code> instead of backticks and explicitly sent it to bash via <code>subprocess.Popen(["/bin/bash", "-c", "echo", "..."]</code>, with the same result.</p>
  
  <p>How can this be solved? I know I can of course use Pythons <code>datetime</code> module in this specific case. But I want to know why this is not working and how to solve it without tearing apart the command. While I'm here able to run the timestamp calculation easily in Python, in other cases it might be more complicated, where I would be forced to run several subprocesses which gets quickly very ugly.</p>