subprocess

Python persistent Popen

Is there a way to do multiple calls in the same "session" in Popen? For instance, can I make a call through it and then another one after it without having to concatenate the commands into one long string? ...

Supplying password to wrapped-up MySQL

Greetings. I have written a little python script that calls MySQL in a subprocess. [Yes, I know that the right approach is to use MySQLdb, but compiling it under OS X Leopard is a pain, and likely more painful if I wanted to use the script on computers of different architectures.] The subprocess technique works, provided that I supply...

python: problem using call.subprocess to use a file after writing it

In python I am trying to write a script that will edit text files and then run executables that use those text files. It basically entails 1)opening and reading/writing to a text file, and 2)using the file I just wrote in a bash command. Here is a simple example: import subprocess # write file a = ['1\n','2\n','3\n','4\n','5th and fi...

How can I run an external command asynchronously from Python?

I need to run a shell command asynchronously from a Python script. By this I mean that I want my Python script to continue running while the external command goes off and does whatever it needs to do. I read this post: http://stackoverflow.com/questions/89228/how-to-call-external-command-in-python I then went off and did some te...

Python, redirecting the stream of Popen to a python function

Dear all, I'm new to python programming. I have this problem: I have a list of text files (both compressed and not) and I need to : - connect to the server and open them - after the opening of the file, I need to take his content and pass it to another python function that I wrote def readLogs (fileName): f = open (fileName, 'r') inStr...

why doesn't subprocess.Popen(...) always return?

I hope this is a simple python question. When I try the following in the python interpreter: >>> import process >>> def test(cmd): ... p = subprocess.Popen(cmd) ... >>> test(['ls', '-l']) It will run the ls -l, but I need to hit "return" to get a new >>> prompt. However, when I try the following: >>> import process >>> def test(c...

Python 2.6 on Windows how to terminate subprocess.Popen with "shell=True" argument?

Is there a way to terminate a process started with the subprocess.Popen class with the "shell" argument set to "True"? In the working minimal example below (uses wxPython) you can open and terminate a Notepad process happily, however if you change the Popen "shell" argument to "True" then the Notepad process doesn't terminate. import w...

How do I print outputs from calls to subprocess.Popen(...) in a loop?

I wrote a script to run a command-line program with different input arguments and grab a certain line from the output. I have the following running in a loop: p1 = subprocess.Popen(["program", args], stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=False) p2 = subprocess.Popen(["grep", phrase], stdin=p1.stdout, stdout=subprocess....

Python's subprocess.Popen returns the same stdout even though it shouldn't

I'm having a very strange issue with Python's subprocess.Popen. I'm using it to call several times an external exe and keep the output in a list. Every time you call this external exe, it will return a different string. However, if I call it several times using Popen, it will always return the SAME string. =:-O It looks like Popen ...

Controlling a Windows Console App w/ stdin pipe

I am trying to control a console application (JTAG app from Segger) from Python using the subprocess module. The application behaves correctly for stdout, but stdin doesn't seem to be read. If enable the shell, I can type into the input and control the application, but I need to do this programmatically. The same code works fine for i...

How do you automate the launching/debugging of large scale projects?

Scenario: There is a complex piece of software that is annoying to launch by hand. What I've done is to create a python script to launch the executable and attach gdb for debugging. The process launching script: ensures an environment variable is set. ensures a local build directory gets added to the environment's LD_LIBRARY_PATH var...

Child process detecting the parent process' death in Python

Is there a way for a child process in Python to detect if the parent process has died? ...

Python subprocess "object has no attribute 'fileno'" error

This code generates "AttributeError: 'Popen' object has no attribute 'fileno'" when run with Python 2.5.1 Code: def get_blame(filename): proc = [] proc.append(Popen(['svn', 'blame', shellquote(filename)], stdout=PIPE)) proc.append(Popen(['tr', '-s', r"'\040'"], stdin=proc[-1]), stdout=PIPE) proc.append(Popen(['tr', r"...

How to use subprocess when multiple arguments contain spaces?

I'm working on a wrapper script that will exercise a vmware executable, allowing for the automation of virtual machine startup/shutdown/register/deregister actions. I'm trying to use subprocess to handle invoking the executable, but the spaces in the executables path and in parameters of the executable are not being handled correctly by...

How do I get 'real-time' information back from a subprocess.Popen in python (2.5)

I'd like to use the subprocess module in the following way: create a new process that potentially takes a long time to execute. capture stdout (or stderr, or potentially both, either together or separately) Process data from the subprocess as it comes in, perhaps firing events on every line recieved (in wxPython say) or simply print...

Is there a way to poll a file handle returned from subprocess.Popen?

Say I write this: from subprocessing import Popen, STDOUT, PIPE p = Popen(["myproc"], stderr=STDOUT, stdout=PIPE) Now if I do line = p.stdout.readline() my program waits until the subprocess outputs the next line. Is there any magic I can do to p.stdout so that I could read the output if it's there, but just continue otherwise? I...

Python: Spawn parallel child processes on a multi-processor system - use multiprocessor package, subprocess package, XYZ package?

Hi there, I am a Python newbie so please be gentle :) I have a Python script that I want to use as a controller to another Python script. I have a server with 64 processors, so want to spawn up to 64 child processes of this second Python script. The child script is called: %> python create_graphs.py --name=NAME where NAME is somethi...

Why won't pylons close the connection if a subprocess is running?

If I try to spawn a process from a pylons controller, the server does not close the connection after sending the reply. Assume that test.py is a long running process, then this method in a pylons controller creates a response, but keeps the connection open: def index(self): from subprocess import Popen Popen(["python", "/temp/t...

Python OSError: [Errno 2]

I have the following code that is attempting to start each of the "commands" below in Linux. The module attempts to keep each of the 2 commands running if either should crash for whatever reason. #!/usr/bin/env python import subprocess commands = [ ["screen -dmS RealmD top"], ["screen -DmS RealmD top -d 5"] ] programs = [ subprocess.Po...

Using subprocess to run Python script on Windows

Is there a simple way to run a Python script on Windows/Linux/OS X? On the latter two, subprocess.Popen("/the/script.py") works, but on Windows I get the following error: Traceback (most recent call last): File "test_functional.py", line 91, in test_functional log = tvnamerifiy(tmp) File "test_functional.py", line 49, in tvname...