subprocess

Running external subprocesses and reading return code

I'm creating a python script to sort a lot of images (game screenshots). I found a way to do that in imagemagick : I know that, if a specific square of the image is the same as the reference crop, then the image is of category one. If not, I check for another crop and another category, and if that doesn't fit either, I put the image in ...

Debugging a subprocess.Popen call

I have been using subprocess.Popen successfully in the past, when wrapping binaries with a python script to format arguments / customize etc... Developing a nth wrapper, I did as usual... but nothing happens. Here is the little code: print command p = subprocess.Popen(command, shell = True) result = p.communicate()[0] print vars(p) re...

Python subprocess get child's output

Possible Duplicates: How to get output from subprocess.Popen() Retrieving the output of subprocess.call() Here is my question. I have an executable called device_console. The device_console provides a command line interface to a device. In device_console, four commands can be run: status, list, clear and exit. Each command p...

Python subprocess/Popen with a modified environment

I believe that running an external command with a slightly modified environment is a very common case. That's how I tend to do it: import subprocess, os my_env = os.environ my_env["PATH"] = "/usr/sbin:/sbin:" + my_env["PATH"] subprocess.Popen(my_command, env=my_env) I've got a gut feeling that there's a better way; does it look alrigh...

subprocess.Popen(..).communicate(..) throw away data at random when used with graphviz!

Hey all! I am using graphviz's dot to generate some svg graphs for a web application. I call dot using Popen: p = subprocess.Popen(u'/usr/bin/dot -Kfdp -Tsvg', shell=True,\ stdin=subprocess.PIPE, stdout=subprocess.PIPE) str = u'long-unicode-string-i-want-to-convert' (stdout,stderr) = p.communicate(str) What happends is...

Different results from converting a file from iso-8859-1 to utf-8 iconv in shell vs calling it from python with subprocess

Well, this could be a simple question, to be frank I'm a little confused with encodings an all those things. Let's suppose I have the file 01234.txt which is iso-8859-1. When I do: iconv --from-code=iso-8859-1 --to-code=utf-8 01234.txt > 01234_utf8.txt It gives me the desired result, but when I do the same thing with python and usin...

Using python to run other programs

I have a command that works great on the command line. It has lots of arguments like cmd --thing foo --stuff bar -a b input output I want to run this from python and block waiting for it to complete. As the script prints things to stdout and stderr I want it to be immediately shown to the user. What is the right module for this? I'v...

piping output of subprocess.Popen to files

I need to launch a number of long-running processes with subprocess.Popen, and would like to have the stdout and stderr from each automatically piped to separate log files. Each process will run simultaneously for several minutes, and I want two log files (stdout and stderr) PER process to be written to as the processes run. Do I need t...

Why does supplying stdin to subprocess.Popen cause what is written to stdout to change?

I'm using Python's subprocess.Popen to perform some FTP using the binary client of the host operating system. I can't use ftplib or any other library for various reasons. The behavior of the binary seems to change if I attach a stdin handler to the Popen instance. For example, using XP's ftp client, which accepts a text file of commands...

Python's subprocessing with pipes and large files.

I'm trying to use python + ffmpeg + oggenc to convert any audiofile to ogg. The program works, almost. But for big files (i think > ~6mb) the ffmpeg process starts to sleep at pipe_wait. I don't know which pipe it waits for. If I kill the ffmpeg process, the oggenc process continues and I get a resulting ogg-file with about ~2:40 of all...

What is the subprocess.Popen max length of the args parameter?

I am using Popen function from the subprocess module to execute a command line tool: subprocess.Popen(args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0) The tool I am using takes a list o...

Use subprocess to send a password

I'm attempting to use the python subprocess module to log in to a secure ftp site and then grab a file. However I keep getting hung up on just trying to send the password when it is requested. I so far have the following code: from subprocess import Popen, PIPE proc = Popen(['sftp','user@server', 'stop'], stdin=PIPE) proc.communicate('...

Why subprocess.Popen doesn't work when args is sequence?

I'm having a problem with subprocess.Popen when args parameter is given as sequence. For example: import subprocess maildir = "/home/support/Maildir" This works (it prints the correct size of /home/support/Maildir dir): size = subprocess.Popen(["du -s -b " + maildir], shell=True, stdout=subprocess.PIPE).commu...

Why is my spawned process still causing IntelliJ to wait?

I'm trying to start a server as part of an Ant artifact. Here are the relevant lines: <exec dir="." executable="cmd.exe" spawn="true"> <arg line="/c c:\Java\james-2.3.2\bin\debug.bat" /> </exec> If I start it with ant from the command line, a process is spawned and I get a command prompt and everything seems fine. Ho...

What is the best way to redirect stdout to NSTextView in Cocoa?

Hi: I want to redirect stdout to a NSTextView. Could this also work with outputs of subprocesses? What might be the best way to achieve this? EDIT: According to Peter Hosey answer I implemented the following. But I do not get a notification. What am I doing wrong? NSPipe *pipe = [NSPipe pipe]; NSFileHandle *pipeHandle = [pipe f...

why does python.subprocess hang after proc.communicate()?

I've got an interactive program called my_own_exe. First, it prints out alive, then you input S\n and then it prints out alive again. Finally you input L\n. It does some processing and exits. However, when I call it from the following python script, the program seemed to hang after printing out the first 'alive'. Can anyone here tell m...

Unbuffered subprocess output (last line missing)

I must be overlooking something terribly obvious. I need to execute a C program, display its output in real time and finally parse its last line, which should be straightforward as the last line printed is always the same. process = subprocess.Popen(args, shell = True, stdout = subprocess.PIPE, stderr = subp...

How to get path to the installed GIT in Python?

I need to get a path to the GIT on Max OS X 10.6 using Python 2.6.1 into script variables. I use this code for that: r = subprocess.Popen(shlex.split("which git"), stdout=subprocess.PIPE) print r.stdout.read() but the problem is that output is empty (I tried stderr too). It works fine with another commands such as pwd or ls. Can any...

How to implement a master/watchdog script in python?

I need it to open 10 processes, and each time one of them finishes I want to wait few seconds and start another one. It seems pretty simple, but somehow I can't get it to work. ...

Python: nonblocking read from stdout of threaded subprocess

I have a script (worker.py) that prints unbuffered output in the form... 1 2 3 . . . n where n is some constant number of iterations a loop in this script will make. In another script (service_controller.py) I start a number of threads, each of which starts a subprocess using subprocess.Popen(stdout=subprocess.PIPE, ...); Now, in my...