Popular recipes tagged "processes" but not "windows"http://code.activestate.com/recipes/tags/processes-windows/2011-10-21T06:44:35-07:00ActiveState Code RecipesSimple invocation of shell commands (Python) 2011-10-21T06:44:35-07:00Nick Coghlanhttp://code.activestate.com/recipes/users/2035254/http://code.activestate.com/recipes/577891-simple-invocation-of-shell-commands/ <p style="color: grey"> Python recipe 577891 by <a href="/recipes/users/2035254/">Nick Coghlan</a> (<a href="/recipes/tags/processes/">processes</a>, <a href="/recipes/tags/shell/">shell</a>). Revision 3. </p> <p>Some simple wrappers around the subprocess functions for use in system administration utilities that frequently need to interpolate trusted data into shell commands (e.g. filenames from directory listings, etc):</p> <pre class="prettyprint"><code>import shellcmd return_code = shellcmd.shell_call('ls -l {}', dirname) listing = shellcmd.check_shell_output('ls -l {}', dirname) </code></pre> <p>Each function invokes the subprocess function of the same name with <code>shell=True</code> and the supplied command string. Any positional and keyword arguments provided to the call are interpolated into the command string with the <code>str.format</code> method.</p>