subprocess

Stdout captured from pipe in Python is truncated

I want to capture the ouput of dpkg --list | grep linux-image in Python 2.6.5 on Ubuntu 10.04. from subprocess import Popen from subprocess import PIPE p1 = Popen(["dpkg", "--list"], stdout=PIPE) p2 = Popen(["grep", "linux-image"], stdin=p1.stdout, stdout=PIPE) stdout = p2.communicate()[0] The content of stdout is: >>> print stdou...

How to run ruby file in the background using Python and get stderr and stout?

I am developing a Python based GUI. I need to run a ruby file and get its output. I did it successfully using subprocess module. But I need to run the file in the background and I need to get its output as well. Can you please let me know how to achieve this? ...

how do I monitor stdout with subprocess in python?

I have a linux application that runs interactively from commandline using stdin to accept commands. I've written a wrapper using subprocess to access stdin while the application is backgrounded. I can now send commands to it using p.stdin.write(command) but how do I go about monitoring its responses? ...

I'm looking for an example on how to use select.select() with subprocess to monitor stdout

Basically, I have an application that is loaded using p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) I can send it commands using p.stdin.write() without any trouble, but I need to monitor stdout for server responses. this whole thing is running inside a tcp server, so I need to know ...

timeout a subprocess

Hi, I realize this might be a duplicate of http://stackoverflow.com/questions/1191374/subprocess-with-timeout. If it is, I apologize, just wanted to clarify something. I'm creating a subprocess, which I want to run for a certain amount of time, and if it doesn't complete within that time, I want it to throw an error. Would something al...

subprocess replacement of popen2 with Python

I tried to run this code from the book 'Python Standard Library' of 'Fred Lunde'. import popen2, string fin, fout = popen2.popen2("sort") fout.write("foo\n") fout.write("bar\n") fout.close() print fin.readline(), print fin.readline(), fin.close() It runs well with a warning of ~/python_standard_library_oreilly_lunde/scripts/pope...

Read multiple lines from subprocess.Popen.stdout

I modified the source code from Fred Lundh's Python Standard Library. The original source uses popen2 to communicate to subprocess, but I changed it to use subprocess.Popen() as follows. import subprocess import string class Chess: "Interface class for chesstool-compatible programs" def __init__(self, engine = "/opt/local/bin...

Debugging a Windows Service and trying to see what it sees

Hi, We currently have an automated system that runs as a service for processing satellite images. This service maintains a configuration file, in the configuration file we apply certain scripts(python) to covnert the input satellite imagery into a more usable format. The scripts call the required applications, for the conversion proces....

python subprocess with shell=True: redirections and platform-independent subprocess killing

Hi, I'm having a hard time getting what I want out of the python subprocess module (which supposed to an unified/platform-independent abstraction, afaik, but don't get me started on that :)). So the simple thing what I'm after is the following. I want to Launch an external (stdio) application (possibly with subprocess), where I use s...

Running mysqldump through Python's subprocess module is slow and verbose

@cost_time def dbdump_all(): "导出数据库所有数据至当前目录下以年月日命名的sql文件" filename=datetime.datetime.now().strftime("%Y-%m-%d") cmd="""mysqldump -u root -pzhoubt --opt --quick --database search > ./%s.sql"""%filename args=shlex.split(cmd) p=subprocess.Popen(args) #stdout, stderr = p.communicate() #print stdout,stderr pri...

Matching Popen.communicate() output with regular expressions doesn't work

I have code that roughly looks like this (the entire code is a bit too long to copy here): import re from subprocess import Popen, PIPE goodOutput = re.compile(r'\S+: 0x[0-9a-fA-F]{8} \d \d\s+->\s+0x[0-9a-fA-F]{8}') p = Popen(['/tmp/myexe', param], stdout=PIPE, stderr=PIPE, cwd='/tmp') stdout, stderr = p.communicate() ret = goodOutp...

how to use subporcess inovke /etc/init.d/tomcat6/ stop in python

i want to invoke /etc/init.d/tomcat6 in subporcess i have tried bellow code,but it didn't work cmd="/etc/init.d/tomcat6/ stop" p=subprocess.Popen(cmd) stdout, stderr = p.communicate() print stdout,stderr anyone could help me,thanks ...

Capturing Console output that is not written to stdout,stderr?

Hi, I have an windows application called pregeocode (we lack source), this program basically writes geocoding to an input file. This program doesn't actually write anything to console unless there is an error. This program is generally called from a small Python program (it handles the arguments etc, and does all the fun preprocessing)....

How do I use subprocess to tar & compress a folder?

I have used the below code, it can compress folders. But when I uncompress folders, it will throw an error. I think there is something wrong with my code. Any advice is welcome. def compress_index(): "将/var/solr/core0/data索引目录进行打包压缩至同目录下,以该日时间命名的data.tar.gz.20101013形式的压缩包" parentdirs,folder=os.path.split(g_index_path) tar_fi...

Python: Parse stream title with mplayer

I'm writing a simple frontend in Python to play and record internet radio channels (e.g. from shoutcast) using mplayer (in a subprocess). When a user clicks a station the following code is run: url = http://77.111.88.131:8010 # only an example cmd = "mplayer %s" % url p = subprocess.Popen(cmd.split(), shell=False) wait = os.waitpid(p....

Subprocess module errors with 'export' in python on linux?

I'm setting up a program to connect my computer to our schools proxy and currently have something like this: import subprocess import sys username = 'fergus.barker' password = '*************' proxy = 'proxy.det.nsw.edu.au:8080' options = '%s:%s@%s' % (username, password, proxy) subprocess.Popen('export http_proxy=' + options) But up...

Getting the entire output from subprocess.Popen

I'm getting a slightly weird result from calling subprocess.Popen that I suspect has a lot to do with me being brand-new to Python. args = [ 'cscript', '%USERPROFILE%\\tools\\jslint.js','%USERPROFILE%\\tools\\jslint.js' ] p = Popen(args, stdout=PIPE, shell=True).communicate()[0] Results in output like the following (the trailing doubl...

Python: How do I redirect this output?

I'm calling rtmpdump via subprocess and trying to redirect its output to a file. The problem is that I simply can't redirect it. I tried first setting up the sys.stdout to the opened file. This works for, say, ls, but not for rtmpdump. I also tried setting the sys.stderr just to make sure and it also didn't work. I tried then using a "...

Very large input and piping using subprocess.Popen

I have pretty simple problem. I have a large file that goes through three steps, a decoding step using an external program, some processing in python, and then recoding using another external program. I have been using subprocess.Popen() to try to do this in python rather than forming unix pipes. However, all the data are buffered to ...

How to start a brand new process in Rails, without inherit current environment variables?

I'm developing an master rails app which controls other rails apps. It has a bash script to start those rails apps, and it works well while it's invoked in the command line manually. But if I invoke it in the matter rails app, using backticks, system, or exec, the script will fail. The error message is: unicorn_rails worker[0] -c ../c...