subprocess

capture stderr from python subprocess.Popen(command, stderr=subprocess.PIPE, stdout=subprocess.PIPE)

I have seen this posted so many times here; yet failed to capture intentional errors from command. Best partial work I have found so far.. from Tkinter import * import os import Image, ImageTk import subprocess as sub p = sub.Popen('datdsade',stdout=sub.PIPE,stderr=sub.PIPE) output, errors = p.communicate() root = Tk() text = Text(root...

How can I capture the stdout output of a child process?

I'm trying to write a program in Python and I'm told to run an .exe file. When this .exe file is run it spits out a lot of data and I need a certain line printed out to the screen. I'm pretty sure I need to use subprocess.popen or something similar but I'm new to subprocess and have no clue. Anyone have an easy way for me to get this don...

Python and subprocess

This is for a script I'm working on. It's supposed to run an .exe file for the loop below. (By the way not sure if it's visible but for el in ('90','52.6223',...) is outside the loop and makes a nested loop with the rest) I'm not sure if the ordering is correct or what not. Also when the .exe file is ran, it spits some stuff out and I ne...

Python 2.6 subprocess.call() appears to be invoking setgid behavior triggering Perl's taint checks. How can I resolve?

I've got some strange behavioral differences between Python's subprocess.call() and os.system() that appears to be related to setgid. The difference is causing Perl's taint checks to be invoked when subprocess.call() is used, which creates problems because I do not have the ability to modify all the Perl scripts that would need untaint c...

During a subprocess call, catch critical windows errors in Python instead of letting the OS handle it by showing nasty error pop-ups

"The application failed to initialize properly ... Click on OK,to terminate the application." is the message from the error pop-up. What is the way to catch these errors in Python code? ...

Python Subprocess.Popen from a thread

I'm trying to launch an 'rsync' using subprocess module and Popen inside of a thread. After I call the rsync I need to read the output as well. I'm using the communicate method to read the output. The code runs fine when I do not use a thread. It appears that when I use a thread it hangs on the communicate call. Another thing I've notice...

Cross-platform subprocess with hidden window

I want to open a process in the background and interact with it, but this process should be invisible in both Linux and Windows. In Windows you have to do some stuff with STARTUPINFO, while this isn't valid in Linux: ValueError: startupinfo is only supported on Windows platforms Is there a simpler way than creating a separate Pope...

Interacting with another command line program in Python.

I need to write a Python script that can run another command line program and interact with it's stdin and stdout streams. Essentially, the Python script will read from the target command line program, intelligently respond by writing to its stdin, and then read the results from the program again. (It would do this repeatedly.) I've loo...

Python - Subprocess - How to call a Piped command in Windows?

How do I run this command with subprocess? I tried: proc = subprocess.Popen( '''ECHO bosco|"C:\Program Files\GNU\GnuPG\gpg.exe" --batch --passphrase-fd 0 --output "c:\docume~1\usi\locals~1\temp\tmptlbxka.txt" --decrypt "test.txt.gpg"''', stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, ) stdout_va...

When I write a python script to run Devenv with configure "Debug|Win32" it does nothing..

Update: When I use the subprocess.call instead of subprocess.Popen, the problem is solved - does anybody know what's the cause? And there came another problem: I can't seem to find a way to control the output... Is there a way to redirect the output from subprocess.call to a string or something like that? Thanks! I'm trying to use Deven...

In Python 2.5, how do I kill a subprocess?

I am using the subprocess package in Python to run a subprocess, which I later need to kill. However, the documentation of the subprocess package states that the terminate() function is only available from 2.6 We are running Linux with 2.5 and for backwards compatibility reasons I cannot upgrade to 2.6, what is the alternative? I am gue...

How to get continuous output of subprocess started using backtick in ruby

I have a ruby application that executes ant as a subprocess using backtick. This works without any problems. When I do puts ant, ruby waits for the subprocess, ant, to finish completely and then prints the output to stdout. How do I get ruby to print the output from the subprocess continuously? ...

Starting and Controlling an External Process via STDIN/STDOUT with Python

I need to launch an external process that is to be controlled via messages sent back and forth via stdin and stdout. Using subprocess.Popen I am able to start the process but am unable to control the execution via stdin as I need to. The flow of what I'm trying to complete is to: Start the external process Iterate for some number o...

How do I run a process from PHP

I need to start a Unix process by calling a PHP-page through the web. I also need to send some arguments to the PHP-page that gets substituted into the command in a save way. ...

Sending SIGINT to a subprocess of python

I've got a python script managing a gdb process on windows, and I need to be able to send a SIGINT to the spawned process in order to halt the target process (managed by gdb) It appears that there is only SIGTERM available in win32, but clearly if I run gdb from the console and Ctrl+C, it thinks it's receiving a SIGINT. Is there a wa...

Python subprocess question

I would like to be able to spawn a process in python and have two way communication. Of course, Pexpect does this and is indeed a way I might go. However, it is not quite ideal. My ideal situation would be to have a cross platform generic technique that involved only the standard python libraries. Subprocess gets pretty close, but the f...

Python: Persistent shell variables in subprocess

I'm trying to execute a series of commands using Pythons subprocess module, however I need to set shell variables with export before running them. Of course the shell doesn't seem to be persistent so when I run a command later those shell variables are lost. Is there any way to go about this? I could create a /bin/sh process, but how wo...

Threads, subprocess & zombies

Hi, I need to launch several remote jobs each at a precise moment using threads and SSH. So I write: def dojob(hostname): command = "echo Done" p = Popen(['ssh','%s@%s' % (user, hostname), command], stdout=PIPE, shell=False) output = p.communicate()[0].strip() print output [...] fire_starter = [Timer(t, dojob, [y]) f...

Stopping a Long-Running Subprocess

I create a subprocess using subprocess.Popen() that runs for a long time. It is called from its own thread, and the thread is blocked until the subprocess completes/returns. I want to be able to interrupt the subprocess so the process terminates when I want. Any ideas? ...

Python: cannot read / write in another commandline application by using subprocess module

I am using Python 3.0 in Windows and trying to automate the testing of a commandline application. The user can type commands in Application Under Test and it returns the output as 2 XML packets. One is a packet and the other one is an packet. By analyzing these packets I can verifyt he result. I ahev the code as below p = subprocess.P...