subprocess

Python Popen difficulties: File not found

I'm trying to use python to run a program. from subprocess import Popen sa_proc = Popen(['C:\\sa\\sa.exe','--?']) Running this small snippit gives the error: WindowsError: [Error 2] The system cannot find the file specified The program exists and I have copy and pasted directly from explorer the absolute path to the exe. I have...

Using subprocess.Popen for Process with Large Output

I have some Python code that executes an external app which works fine when the app has a small amount of output, but hangs when there is a lot. My code looks like: p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) errcode = p.wait() retval = p.stdout.read() errmess = p.stderr.read() if errcode: l...

subprocess with timeout

In Python, I have a program snippet similar to the following that has the effect of running a custom command and returning the stdout data (or raise exception when exit code is non-zero): proc = subprocess.Popen( cmd, # keep stderr separate; or merge it with stdout (default). stderr=(subprocess.PIPE if ignore_stderr else sub...

How to get environment from a subprocess in Python

I want to call a process via a python program, however, this process need some specific environment variables that are set by another process. How can I get the first process environment variables to pass them to the second? This is what the program look like: import subprocess subprocess.call(['proc1']) # this set env. variables for ...

Find the current stdout OR How to redirect the output back to console.

I'm using Ubuntu 9.04 x64 and, I have a file startup.rb in which I call sudo bash, so that I always have a root console to do administrative tasks without typing password after every 15 minutes or so. This script is called by another script Startup.rb, and content of both files are like this - File ~/Startup.rb #!/usr/bin/ruby system...

subprocess: deleting child processes in Windows

On Windows, subprocess.Popen.terminate calls win32's TerminalProcess. However, the behavior I see is that child processes of the process I am trying to terminate is still running. Why is that? How do I ensure killing every god damn processes started by the process? ...

Disable console output from subprocess.Popen in Python

I run Python 2.5 on Windows, and somewhere in the code I have subprocess.Popen("taskkill /PID " + str(p.pid)) to kill IE window by pid. The problem is that without setting up piping in Popen I still get output to console - SUCCESS: The process with PID 2068 has been terminated. I debugged it to CreateProcess in subprocess.py, but can'...

Why does subprocess.Popen() with shell=True work differently on Linux vs Windows?

When using subprocess.Popen(args, shell=True) to run "gcc --version" (just as an example), on Windows we get this: >>> from subprocess import Popen >>> Popen(['gcc', '--version'], shell=True) gcc (GCC) 3.4.5 (mingw-vista special r3) ... So it's nicely printing out the version as I expect. But on Linux we get this: >>> from subprocess...

Python Subprocess - Redirect stdout/err to two places

Hi, I have a small python script which invokes an external process using subprocess. I want to redirect stdout and stderr to both a log file and to the terminal. How can this be done? Thanks, Udi ...

python subprocess module: looping over stdout of child process

I have some commands which I am running using the subprocess module. I then want to loop over the lines of the output. The documentation says do not do data_stream.stdout.read which I am not but I may be doing something which calls that. I am looping over the output like this: for line in data_stream.stdout: #do stuff here . ...

Piping output of subprocess.call to progress bar

I'm using growisofs to burn an iso through my Python application. I have two classes in two different files; GUI() (main.py) and Boxblaze() (core.py). GUI() builds the window and handles all the events and stuff, and Boxblaze() has all the methods that GUI() calls. Now when the user has selected the device to burn with, and the file to...

What does <() do in Bash?

In a post's answer on superuser.com, we see that join <(sort abc) <(sort bcd) will sort files abc and bcd before sending them to join. This leads to a programming question, better suited for stackoverflow. How does this work? What exactly is this <() construct? What's it called? If (sort abc) is a legal call that runs sort on abc ...

Implementing the "system" command in Java.

I have need for a "system" function call, the same as those in Python, Perl, PHP, Ruby, &c. It will be a component of a JavaScript standard library called Narwhal, when it's run on the Rhino JavaScript engine, which is in turn run on Java. The trouble is that Java's standard library appears to have abstracted away the ability to spawn ...

Python subprocess with heredocs

I was playing around with Python's subprocess module, trying a few examples but I can't seem to get heredoc statements to work. Here is the trivial example I was playing with: import subprocess a = "A String of Text" p = subprocess.Popen(["cat", "<<DATA\n" + a + "\nDATA"]) I get the following error when I run the code above: cat: <<...

Problem with subprocess.call

In my current working directory I have the dir ROOT/ with some files inside. I know I can exec cp -r ROOT/* /dst and I have no problems. But if I open my Python console and I write this: import subprocess subprocess.call(['cp', '-r', 'ROOT/*', '/dst']) It doesn't work! I have this error: cp: cannot stat ROOT/*: No such file or dire...

Call a function from a running process

Hi, my programm starts a subprocess, which has to send some kind of signal to the parent after initialization. It would be perfekt if i could set up a handler in parent, which is called when this signal is sent. Is there any way to do it? Alendit ...

Create an executable process without using shell on Python 2.5 and below

Just what the title says: The subprocess module cannot be used as this should work on 2.4 and 2.5 Shell process should not be spawned to pass arguments. To explain (2), consider the following code: >>> x=os.system('foo arg') sh: foo: not found >>> x=os.popen('foo arg') sh: foo: not found >>> As you can see os.system and os.popen r...

Track process status with Python

hello, I want to start a number of subprocesses in my Python script and then track when they complete or crash. subprocess.Popen.poll() seems to return None when the process is still running, 0 on success, and non-zero on failure. Can that be expected on all OS's? Unfortunately the standard library documentation is lacking for these me...

In Django, how to call a subprocess with a slow start-up time.

Suppose you're running Django on Linux, and you've got a view, and you want that view to return the data from a subprocess called cmd that operates on a file that the view creates, for example likeso: def call_subprocess(request): response = HttpResponse() with tempfile.NamedTemporaryFile("W") as f: f.write(request....

How can I find out why subprocess.Popen wait() waits forever if stdout=PIPE?

I have a program that writes to stdout and possibly stderr. I want to run it from python, capturing the stdout and stderr. My code looks like: from subprocess import * p = Popen( exe, shell=TRUE, stdout=PIPE, stderr=PIPE ) rtrncode = p.wait() For a couple of programs, this works fine, but when I added a new one, the new one hangs for...