title: How to check if a string is a valid shell command using Python?
body: <p>I am making a program that adds additional functionality to the standard command shell in Windows. For instance, typing <code>google</code> followed by keywords will open a new tab with Google search for those keywords, etc. Whenever the input doesn't refer to a custom function I've created, it gets processed as a shell command using <code>subprocess.call(rawCommand, shell=True)</code>.</p>
  <p>Since I'd like to anticipate when my input isn't a valid command and return something like <code>f&quot;Invalid command: {rawCommand}&quot;</code>, how should I go about doing that?</p>
  <p>So far I've tried <code>subprocess.call(rawCommand)</code> which also return the standard output as well as the exit code. So that looks like this:</p>
  <pre><code>&gt;&gt;&gt; from subprocess import call
  &gt;&gt;&gt; a, b = call(&quot;echo hello!&quot;, shell=1), call(&quot;xyz arg1 arg2&quot;, shell=1)
  hello!
  'xyz' is not recognized as an internal or external command,
  operable program or batch file.
  &gt;&gt;&gt; a
  0
  &gt;&gt;&gt; b
  1
  </code></pre>
  <p>I'd like to simply recieve that exit code. Any ideas on how I can do this?</p>