subprocess

Running external commands in IPython

I'd like to run a new command from IPython configuration and capture its output. Basically, I'd like to access the equivalent of !command via normal functions. I know I can just use subprocess, but since IPython already provides this functionality, I guess there must be a properly made wrapper included somewhere in the API. ...

Calling bash functions from sub process

Hi, I'm not sure if its possible, but I'm looking for a way to call a bash function from its subprocess. It could be something like: function testfunc() { echo test function; } bash -c 'testfunc' This doesn't work obviously, but is there any way to achieve something like this? Thanks a lot for the help! ...

Subprocess.Popen hangs with interactive programs when called from inside Django

Hi, I have written a small Django App, that executes an interactive program based on user input and returns the output as the result. But for some reason, the subprocess hangs. On verification of the logs I found that a place where a '\n' has to be given as repsonse to a challenge, the response seems to have never been made. Interesting...

Trying to call readline() on a file object in python but it's pausing

I'm using the readline() function to read data from a file object obtained through the subprocess module: proc = subprocess.Popen(cmd, bufsize=0, stdout=subprocess.PIPE). This allows me to use proc.stdout as a file-like object with proc.stdout.readline(). My issue is that this pauses waiting for input and I'd like it to time out and m...

Can subprocess.Popen be used when called from py code running under mod_wsgi in Apache2

Hi, I'm using subprocess.Popen and getting IOErrors when running under mod_wsgi. The following code will work in a python term, or a django runserver, and under mod_python. If you put it under mod_wsgi (v2), it fails: (2, 'No such file or directory') I have tried many variations involving using subprocess.PIPE. I have tried to red...

Communicating multiple times with a subprocess

I'm trying to pipe input to a program opened as a subprocess in Python. Using communicate() does what I want, but it only does so once, then waits for the subprocess to terminate before allowing things to continue. Is there a method or module similar to communicate() in function, but allows multiple communications with the child proces...

How to get two python processes talking over pipes?

Hi, I'm having troubles getting this to work. Basically I have a python program that expect some data in stdin, that is reading it as sys.stdin.readlines() I have tested this and it is working without problems with things like echo "" | myprogram.py I have a second program that using the subprocess module calls on the first program wit...

Python subprocess.Popen communicate through a pipeline

I want to be able to use Popen.communicate and have the stdout logged to a file (in addition to being returned from communicate(). This does what I want - but is it really a good idea? cat_task = subprocess.Popen(["cat"], stdout=subprocess.PIPE, stdin=subprocess.PIPE) tee_task = subprocess.Popen(["tee", "-a", "/tmp/logcmd"], stdin=cat...

subprocess.Popen() has inconsistent behavior between Eclipse/PyCharm and terminal execution

The problem I'm having is with Eclipse/PyCharm interpreting the results of subprocess's Popen() differently from a standard terminal. All are using python2.6.1 on OSX. Here's a simple example script: import subprocess args = ["/usr/bin/which", "git"] print "Will execute %s" % " ".join(args) try: p = subprocess.Popen(["/usr/bin/which...

What is the subprocess equivalent of passing "b" to os.popen2?

In Python 2.x, os.popen(command, "b") gives me a binary stream of the given command's output. This is primarily important on Windows, where binary and text streams actually give you different bytes. The subprocess module is supposed to replace os.popen and the other child-process spawning APIs. However, the conversion docs don't talk ...

Python: Why does subprocess() start 2 processes in Ubuntu, and 1 in OpenSUSE?

I've written small gui-frontend in Python that lets users play internet radio channels. The program uses Pythons subprocess() to initizalize mplayer in order to tune into a channel, e.g.: runn = "mplayer http://77.111.88.131:8010" p = subprocess.Popen(runn, shell=True) pid = int(p.pid) wait = os.waitpid(p.pid, 1) Then saves p.pid, and ...

How do I make this compatible with Windows?

Good day, Stackoverflow! I have a little (big) problem with porting one of my Python scripts for Linux to Windows. The hairy thing about this is that I have to start a process and redirect all of its streams into pipes that I go over and read and write to and from in my script. With Linux this is a piece of cake: server_startcmd = [ ...

Start a script on a remote machine through ssh with python - but in reverse?

Here's what I need to do: The user is on a remote machine and connects to a server via ssh. He runs a python script on the server. The script running on the server starts a script on the user's remote machine as a subprocess and opens a pipe to it for communication. First, is this at all possible? Second, is this possible in such a ...

Delaying Cocoa NSDocument creation at startup

I have a document-based Cocoa application that has to start up a sub-process before running. It would be best if that process could finish starting up before I display any document windows. I get a notification when the process has fully started. How can I delay the creation of the untitled NSDocument subclass object until the notific...

Retrieving stdout from subprocess in Windows.

I can call FFmpeg with subprocess.Popen and retrieve the data I need, as it occurs (to get progress), but only in console. I've looked around and seen that you can't get the data "live" when running with pythonw. Yet, waiting until the process finishes to retrieve the data is moot, since I'm trying to wrap a PyQT GUI around FFmpeg so I c...

Multi processing subprocess

i am new to subprocess module of python, currently my implementation is not multi processed. import subprocess,shlex def forcedParsing(fname): cmd = 'strings "%s"' % (fname) #print cmd args= shlex.split(cmd) try: sp = subprocess.Popen( args, shell = False, stdout = subprocess.PIPE, stderr...

python + windows: run exe as if it's unrelated to the current process

I know I can use subprocess.Popen to run an executable, and potentially redirect stdin and stdout to files / using pipes to my process. Is there a way to run an executable such that the spawned process has no relation to the current Python process, however? Meaning, I want to start a process in the same way as if I would double-click on ...

Passing a password to KLOG from within a script, using `subprocess.POPEN`

Hello: A series of applications I'm writing require that the user be able to read from a filesystem with KLOG authentication. Some functions require the user to have KLOG tokens (i.e., be authenticated) and others don't. I wrote a small Python decorator so that I can refactor the "you must be KLOGed" functionality within my modules: # ...

python subprocess with timeout and large output (>64K)

I want to execute a process, limit the execution-time by some timeout in seconds and grab the output produced by the process. And I want to do this on windows, linux and freebsd. I have tried implementing this in three different ways: cmd - Without timeout and subprocess.PIPE for output capture. BEHAVIOUR: Operates as expected but do...

Running piped subprocesses gives different result when the launch order changes ?

Hello, I'm running a pipe of commands from a python3 program, using subprocess.*; I didn't want to go trough a shell, for I'm passing arguments to my subcommands, and making sure these would not be misinterpreted by the shell would be nightmarish. The subprocess doc gives this example of how to do it: p1 = Popen(command1, stdout=PIPE)...