Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two ways to do the redirect. Both apply to either <code>subprocess.Popen</code> or <code>subprocess.call</code>.</p> <ol> <li><p>Set the keyword argument <code>shell = True</code> or <code>executable = /path/to/the/shell</code> and specify the command just as you have it there.</p></li> <li><p>Since you're just redirecting the output to a file, set the keyword argument</p> <pre><code>stdout = an_open_writeable_file_object </code></pre> <p>where the object points to the <code>output</code> file.</p></li> </ol> <p><a href="http://docs.python.org/library/subprocess.html#subprocess.Popen" rel="noreferrer"><code>subprocess.Popen</code></a> is more general than <a href="http://docs.python.org/library/subprocess.html#subprocess.call" rel="noreferrer"><code>subprocess.call</code></a>.</p> <p><code>Popen</code> doesn't block, allowing you to interact with the process while it's running, or continue with other things in your Python program. The call to <code>Popen</code> returns a <code>Popen</code> object.</p> <p><code>call</code> <em>does</em> block. While it supports all the same arguments as the <code>Popen</code> constructor, so you can still set the process' output, environmental variables, etc., your script waits for the program to complete, and <code>call</code> returns a code representing the process' exit status. </p> <pre><code>returncode = call(*args, **kwargs) </code></pre> <p>is basically the same as calling </p> <pre><code>returncode = Popen(*args, **kwargs).wait() </code></pre> <p><code>call</code> is just a convenience function. It's implementation in CPython is in <a href="http://hg.python.org/cpython/file/e0df7db13d55/Lib/subprocess.py#l459" rel="noreferrer">subprocess.py</a>:</p> <pre><code>def call(*popenargs, timeout=None, **kwargs): """Run command with arguments. Wait for command to complete or timeout, then return the returncode attribute. The arguments are the same as for the Popen constructor. Example: retcode = call(["ls", "-l"]) """ with Popen(*popenargs, **kwargs) as p: try: return p.wait(timeout=timeout) except: p.kill() p.wait() raise </code></pre> <p>As you can see, it's a thin wrapper around <code>Popen</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload