Most viewed recipes tagged "subprocess"http://code.activestate.com/recipes/tags/subprocess/views/2015-05-19T19:31:59-07:00ActiveState Code RecipesPython subprocess: hide console on Windows (Python)
2013-07-29T05:33:49-07:00Esteban Castro Borsanihttp://code.activestate.com/recipes/users/4184010/http://code.activestate.com/recipes/578300-python-subprocess-hide-console-on-windows/
<p style="color: grey">
Python
recipe 578300
by <a href="/recipes/users/4184010/">Esteban Castro Borsani</a>
(<a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/subprocess/">subprocess</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>It creates a new <em>hidden</em> window, so it will work in frozen apps (.exe).</p>
Subprocess with async I/O pipes class (Python)
2009-05-17T02:02:04-07:00Mike Kazantsevhttp://code.activestate.com/recipes/users/4170279/http://code.activestate.com/recipes/576759-subprocess-with-async-io-pipes-class/
<p style="color: grey">
Python
recipe 576759
by <a href="/recipes/users/4170279/">Mike Kazantsev</a>
(<a href="/recipes/tags/asynchronous/">asynchronous</a>, <a href="/recipes/tags/ipc/">ipc</a>, <a href="/recipes/tags/non_blocking_i_o/">non_blocking_i_o</a>, <a href="/recipes/tags/pipe/">pipe</a>, <a href="/recipes/tags/subprocess/">subprocess</a>).
Revision 2.
</p>
<p>Just stumbled upon the need to move data chunks between subprocesses in a non-linear way with some logic in-between, so tee(1) and fifo(7)'s weren't too good option.
Inspired by 440554, but rewritten from scratch to remove unnecessary delays due to sleep(3) calls and suboptimal try/sleep-based polling.</p>
Asynchronous subprocess using asyncore (Python)
2013-01-21T19:51:00-08:00Glenn Eychanerhttp://code.activestate.com/recipes/users/4172294/http://code.activestate.com/recipes/576957-asynchronous-subprocess-using-asyncore/
<p style="color: grey">
Python
recipe 576957
by <a href="/recipes/users/4172294/">Glenn Eychaner</a>
(<a href="/recipes/tags/async/">async</a>, <a href="/recipes/tags/asynchronous/">asynchronous</a>, <a href="/recipes/tags/asyncore/">asyncore</a>, <a href="/recipes/tags/coroutine/">coroutine</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/ipc/">ipc</a>, <a href="/recipes/tags/subprocess/">subprocess</a>).
Revision 21.
</p>
<p>A coroutine-based wrapper for subprocess.Popen that uses asyncore to communicate with child processes asynchronously. This allows subprocesses to be called from within socket servers or clients without needing a complicated event loop to check both. Uses <a href="http://code.activestate.com/recipes/576965/">recipe 576965</a> to provide the asynchronous coroutine framework, <a href="http://code.activestate.com/recipes/576967/">recipe 576967</a> to provide asynchronous pipes, and <a href="http://code.activestate.com/recipes/577600/">recipe 577600</a> to provide multiple alarms.</p>
Run OS command with timeout on a list of files using several threads (Python)
2015-05-19T19:31:59-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/579056-run-os-command-with-timeout-on-a-list-of-files-usi/
<p style="color: grey">
Python
recipe 579056
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/subprocess/">subprocess</a>, <a href="/recipes/tags/threading/">threading</a>).
Revision 3.
</p>
<p>This hack runs a command sequentially on a list of files using two simultaneous threads. If one of the commands takes more than a set time, it's killed and the program goes for the next file. EDITED to add some exception handling.</p>
Threaded communication with subprocess (Python)
2013-03-13T06:06:16-07:00Jan Müllerhttp://code.activestate.com/recipes/users/4183984/http://code.activestate.com/recipes/578488-threaded-communication-with-subprocess/
<p style="color: grey">
Python
recipe 578488
by <a href="/recipes/users/4183984/">Jan Müller</a>
(<a href="/recipes/tags/async/">async</a>, <a href="/recipes/tags/ipc/">ipc</a>, <a href="/recipes/tags/messaging/">messaging</a>, <a href="/recipes/tags/multithreading/">multithreading</a>, <a href="/recipes/tags/pipe/">pipe</a>, <a href="/recipes/tags/queue/">queue</a>, <a href="/recipes/tags/subprocess/">subprocess</a>).
Revision 3.
</p>
<p>This recipe shows how to domesticate another executable as a service in a subprocess.</p>
Subprocess As Another User (Python)
2010-12-23T00:10:08-08:00Eric Pruitthttp://code.activestate.com/recipes/users/4170757/http://code.activestate.com/recipes/577495-subprocess-as-another-user/
<p style="color: grey">
Python
recipe 577495
by <a href="/recipes/users/4170757/">Eric Pruitt</a>
(<a href="/recipes/tags/login/">login</a>, <a href="/recipes/tags/subprocess/">subprocess</a>, <a href="/recipes/tags/user/">user</a>, <a href="/recipes/tags/windows/">windows</a>).
Revision 3.
</p>
<p>Modifies the subprocess module and supplies a new class, LoginSTARTUPINFO, to launch processes as another user on Windows. Requires the pywin32 libraries, but the system ../lib/subprocess.py does not need to be modified.</p>
<pre class="prettyprint"><code>>>> import subprocesswin32 as subprocess
>>> sysuser = LoginSTARTUPINFO("username", "machine", "passwd123")
>>> stdout, stderr = subprocess.Popen("cmd.exe", stdout=subprocess.PIPE,
... startupinfo=sysuser).communicate()
</code></pre>
unix subprocess wrapper (Python)
2008-07-29T07:11:17-07:00Pádraig Bradyhttp://code.activestate.com/recipes/users/1890175/http://code.activestate.com/recipes/576387-unix-subprocess-wrapper/
<p style="color: grey">
Python
recipe 576387
by <a href="/recipes/users/1890175/">Pádraig Brady</a>
(<a href="/recipes/tags/group/">group</a>, <a href="/recipes/tags/popen/">popen</a>, <a href="/recipes/tags/subprocess/">subprocess</a>, <a href="/recipes/tags/unix/">unix</a>).
Revision 2.
</p>
<p>I have used this for ages to control child processes (and all their children). Some of the existing subprocess module was based on this, but I find this simpler for my uses at least.</p>
<h4>Example:</h4>
<pre class="prettyprint"><code>import subProcess
process = subProcess.subProcess("your shell command")
process.read() #timeout is optional
handle(process.outdata, process.errdata)
del(process)
</code></pre>
Async subprocess check_output replacement for Twisted (Python)
2012-01-20T09:48:27-08:00Alan Franzonihttp://code.activestate.com/recipes/users/4169882/http://code.activestate.com/recipes/578021-async-subprocess-check_output-replacement-for-twis/
<p style="color: grey">
Python
recipe 578021
by <a href="/recipes/users/4169882/">Alan Franzoni</a>
(<a href="/recipes/tags/check_output/">check_output</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/spawnprocess/">spawnprocess</a>, <a href="/recipes/tags/subprocess/">subprocess</a>, <a href="/recipes/tags/twisted/">twisted</a>).
</p>
<p>As any twisted user knows, the original python subprocess module can yield to interferences with twisted's own reactor - at least unless installSignalHandlers is false, which can lead to other consequences. </p>
<p>This recipe simulates a stripped down version of subprocess.check_output() which returns a deferred and is twisted friendly.</p>
subprocess.terminate() not always implemented (Python)
2009-02-25T10:45:01-08:00Gui Rhttp://code.activestate.com/recipes/users/4166241/http://code.activestate.com/recipes/576667-subprocessterminate-not-always-implemented/
<p style="color: grey">
Python
recipe 576667
by <a href="/recipes/users/4166241/">Gui R</a>
(<a href="/recipes/tags/process_management/">process_management</a>, <a href="/recipes/tags/subprocess/">subprocess</a>, <a href="/recipes/tags/terminate/">terminate</a>).
Revision 2.
</p>
<p>The new subprocess module brings clarity and simplicity over the popenXX() functions and os.spawnXX() functions, but some implementations don't have the subprocess.terminate() method, which is crucial for killing a spawned process. This workaround works on both POSIX and Windows.</p>
A Basic USe flag EDitor for Gentoo Linux supporting on-the-fly editing (Python)
2015-02-28T07:04:31-08:00Mike 'Fuzzy' Partinhttp://code.activestate.com/recipes/users/4179778/http://code.activestate.com/recipes/579028-a-basic-use-flag-editor-for-gentoo-linux-supportin/
<p style="color: grey">
Python
recipe 579028
by <a href="/recipes/users/4179778/">Mike 'Fuzzy' Partin</a>
(<a href="/recipes/tags/parsing/">parsing</a>, <a href="/recipes/tags/popen/">popen</a>, <a href="/recipes/tags/subprocess/">subprocess</a>, <a href="/recipes/tags/user_input/">user_input</a>).
</p>
<p>This allows for on-the-fly editing. Simply drop abused.py into your path, and ensure that -a is not set in EMERGE_DEFAULT_OPTS in /etc/portage/make.conf. Then whenver you are installing new packages, use abused in place of emerge (eg: abused multitail) you will be presented with a list of use flags that are used in this action, and a prompt for editing any of them, simply hit enter with no changes to fire off the build.</p>
Decoupled Proxy of a State Bearing Object in a Multiprocessing Environment (Python)
2010-04-08T04:36:05-07:00Mateyuzohttp://code.activestate.com/recipes/users/4172453/http://code.activestate.com/recipes/577180-decoupled-proxy-of-a-state-bearing-object-in-a-mul/
<p style="color: grey">
Python
recipe 577180
by <a href="/recipes/users/4172453/">Mateyuzo</a>
(<a href="/recipes/tags/access/">access</a>, <a href="/recipes/tags/multiprocessing/">multiprocessing</a>, <a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/processing/">processing</a>, <a href="/recipes/tags/subprocess/">subprocess</a>, <a href="/recipes/tags/synchronization/">synchronization</a>, <a href="/recipes/tags/syncmanager/">syncmanager</a>, <a href="/recipes/tags/threading/">threading</a>, <a href="/recipes/tags/__getattribute__/">__getattribute__</a>).
Revision 2.
</p>
<p>Describes a simple example of the potential for shared Singleton or Borg object methods to be proxy'd by an object that SyncManger can present to requesting subprocesses.</p>
rdd (mostly broken but shows how to do a few things in ruby) (Ruby)
2014-07-12T16:58:06-07:00Mike 'Fuzzy' Partinhttp://code.activestate.com/recipes/users/4179778/http://code.activestate.com/recipes/578034-rdd-mostly-broken-but-shows-how-to-do-a-few-things/
<p style="color: grey">
Ruby
recipe 578034
by <a href="/recipes/users/4179778/">Mike 'Fuzzy' Partin</a>
(<a href="/recipes/tags/dd/">dd</a>, <a href="/recipes/tags/ftp/">ftp</a>, <a href="/recipes/tags/io/">io</a>, <a href="/recipes/tags/net_ftp/">net_ftp</a>, <a href="/recipes/tags/pipe/">pipe</a>, <a href="/recipes/tags/pipelining/">pipelining</a>, <a href="/recipes/tags/popen/">popen</a>, <a href="/recipes/tags/subprocess/">subprocess</a>).
Revision 3.
</p>
<p>Meant to be a slightly more "advanced" dd utility. Supporting FTP/File/STDIN as input streams, and File/STDOUT/PIPE as output targets, and sporting a progress display (very rudimentary atm), add lets you combine network, and file or pipe processing in a single command. But kind of ended up a mess, see the <a href="https://code.activestate.com/recipes/578907-python-awesome-dd/?in=user-4179778">Python version</a> which is pretty clean.</p>