title: In Python: how can I get the exit status of the previous process run from Bash (i.e. "$?")?
body: <p>I have a Python script that should report success or failure of the previous command. Currently, I'm doing</p>
  <pre class="lang-none prettyprint-override"><code>command &amp;&amp; myscript &quot;Success&quot; || myscript &quot;Failed&quot;
  </code></pre>
  <p>What I would like to do is instead to be able to run the commands unlinked as in:</p>
  <pre class="lang-none prettyprint-override"><code>command; myscript
  </code></pre>
  <p>And have <code>myscript</code> retrieve <code>$?</code>, i.e. the exist status. I know I could run:</p>
  <pre class="lang-none prettyprint-override"><code>command; myscript $?
  </code></pre>
  <p>But what I'm really looking for is a Python way to retrieve <code>$?</code> from Python.</p>
  <p>How can I do it?</p>
  <hr/>
  <p>Since this is a strange request, let me clarify where it comes from. I have a Python script that uses the <a href="https://pushover.net/" rel="nofollow noreferrer">pushover</a> API to send a notification to my phone.</p>
  <p>When I run a long process, I run it as <code>process &amp;&amp; notify &quot;success&quot; || notify &quot;failure&quot;</code>. But sometimes I forget to do this and just run the process. At this point, I'd like to run &quot;notify&quot; on the still processing command line, and have it pick up the exit status and notify me.</p>
  <p>Of course I could also implement the pushover API call in bash, but now it's become a question of figuring out how to do it in Python.</p>