subprocess

What's the best way to duplicate fork() in windows?

How do I implement some logic that will allow me to duplicate the functionality on windows that I have on linux with fork() using python? I'm specifically trying to execute a method on the SAPI Com component, while continuing the other logic in the main thread without blocking or waiting. ...

Why is the subprocess.Popen class not named Subprocess?

The primary class in the subprocess module is name Popen, and represents a subprocess. Popen sounds like someone was trying to force the name to follow some function naming format, rather than chosing a name that actually represents what the object is. Does anyone know why it was chosen over something simple like, say, Subprocess? ...

Python - How do I pass a string into subprocess.Popen (using the stdin argument)?

If I do the following: import subprocess from cStringIO import StringIO subprocess.Popen(['grep','f'],stdout=subprocess.PIPE,stdin=StringIO('one\ntwo\nthree\nfour\nfive\nsix\n')).communicate()[0] I get: Traceback (most recent call last): File "<stdin>", line 1, in ? File "/build/toolchain/mac32/python-2.4.3/lib/python2.4/subproce...

Is it possible to communicate with a sub subprocess with subprocess.Popen?

I'm trying to write a python script that packages our software. This script needs to build our product, and package it. Currently we have other scripts that do each piece individually which include csh, and perl scripts. One such script is run like: sudo mod args where mod is a perl script; so in python I would do proc = Popen(['sud...

How do I get rid of Java child processes when my Java app exits/crashes?

I launch a child process in Java as follows: final String[] cmd = {"<childProcessName>"}; Process process = Runtime.getRuntime().exec(cmd); It now runs in the background. All good and fine. If my program now crashes (it is still in dev :-)) the child process still seems to hang around. How can I make it automatically end when the pa...

What's the difference between all of the os.popen() methods?

I was looking at the Python documentation and saw that there are 4-5 different versions of popen(), e.g. os.popen(), os.popen2(), etc. Apart from the fact that some include stderr while others don't, what are the differences between them and when would you use each one? The documentation didn't really explain it very well. ...

How do I use subprocess.Popen to connect multiple processes by pipes?

How do I execute the following shell command using the Python subprocess module? echo "input data" | awk -f script.awk | sort > outfile.txt The input data will come from a string, so I don't actually need echo. I've got this far, can anyone explain how I get it to pipe through sort too? p_awk = subprocess.Popen(["awk","-f","script.a...

Ensuring subprocesses are dead on exiting Python program

Is there a way to ensure all created subprocess are dead at exit time of a Python program? By subprocess I mean those created with subprocess.Popen(). If not, should I iterate over all of the issuing kills and then kills -9? anything cleaner? ...

Launch a shell command with in a python script, wait for the termination and return to the script

I've a python script that has to launch a shell command for every file in a dir: import os files = os.listdir(".") for f in files: os.execlp("myscript", "myscript", f) This works fine for the first file, but after the "myscript" command has ended, the execution stops and does not come back to the python script. How can I do? Do ...

Python, Popen and select - waiting for a process to terminate or a timeout

I run a subprocess using: p = subprocess.Popen("subprocess", stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdid=subprocess.PIPE) This subprocess could either exit immediately with an error on stderr, or keep running. I want to detect either of these condition...

Python subprocess.call() fails when using pythonw.exe

I have some Python code that works correctly when I use python.exe to run it, but fails if I use pythonw.exe. def runStuff(commandLine): outputFileName = 'somefile.txt' outputFile = open(outputFileName, "w") try: result = subprocess.call(commandLine, shell=True, stdout=outputFile) except...

How to launch multiple subprocesses sequentially in python ?

I would like to execute multiple commands in a row: ie (just to illustrate my need): cmd (the shell) then cd dir and ls and read the result of the ls. Any idea with subprocess module ? UPDATE: cd dir and ls are just an example. I need to run complex commands (following a particular order, without any pipelining). In fact, i wou...

Non-blocking read on a stream in python.

Hi, I'm using the subprocess module to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-bloking or to check if there is data on the stream before I invoke .readline? I'd like this to be portable or at least work under Window...

Prevent Python subprocess from passing fds on Windows?

Python's subprocess module by default passes all open file descriptors to any child processes it spawns. This means that if the parent process is listening on a port, and is killed, it cannot restart and begin listening again (even using SO_REUSEADDR) because the child is still in possession of that descriptor. I have no control over t...

Spawn subprocess that expects console input without blocking?

Hello, I am trying to do a CVS login from Python by calling the cvs.exe process. When calling cvs.exe by hand, it prints a message to the console and then waits for the user to input the password. When calling it with subprocess.Popen, I've noticed that the call blocks. The code is subprocess.Popen(cvscmd, shell = True, stdin = subp...

subprocess.Popen

I am running an msi installer in silent mode and caching logs in the specific file. the following is the command i need to execute. C:\Program Files\ My Installer\Setup.exe /s /v "/qn /lv %TEMP%\log_silent.log" I used: subprocess.Popen(['C:\Program Files\ My Installer\Setup.exe', '/s /v "/qn /lv %TEMP%\log_silent.log"'],stdout=subpro...

intercepting stdout of a subprocess while it is running

if this is my subprocess: import time, sys for i in range(200): sys.stdout.write( 'reading %i\n'%i ) time.sleep(.02) And this is the script controlling and modifying the output of the subprocess: import subprocess, time, sys print 'starting' proc = subprocess.Popen( 'c:/test_apps/testcr.py', shell=True, stdin=su...

How do I run another script in Python without waiting for it to finish?

I am creating a little dashboard for a user that will allow him to run specific jobs. I am using Django so I want him to be able to click a link to start the job and then return the page back to him with a message that the job is running. The results of the job will be emailed to him later. I believe I am supposed to use subprocess.Po...

How can I update a win32 app gui while it is waiting for another program to finish?

I am currently using CreateProcess/WaitForSingleObject from within a win32 GUI app to launch a small GUI app that deals with software licensing issues. This all works fine, but it essentially hangs the "parent" app while it waits for the licensing app to finish its work. During this time, updates to the parent app do not occur and it end...

running a command as a super user from a python script

Heyas So I'm trying to get a process to be run as a super user from within a python script using subprocess. In the ipython shell something like proc = subprocess.Popen('sudo apach2ctl restart', shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) works fine, but as soon as I stick it into a script I st...