popen

Is it possible to run function in a subprocess without threading or writing a separate file/script.

import subprocess def my_function(x): return x + 100 output = subprocess.Popen(my_function, 1) #I would like to pass the function object and its arguments print output #desired output: 101 I have only found documentation on opening subprocesses using separate scripts. Does anyone know how to pass function objects or even an easy...

Recover process with subprocess.Popen?

Hi everyone! I have a python program that uses subprocess.Popen to launch another process (python process or whatever), and after launching it I save the child's PID to a file. Let's suppose that suddenly the parent process dies (because of an exception or whatever). Is there any way to access again to the object returned by Popen? I m...

subprocess popen + curl + binary data

The following statement works as expected: os.system("curl --data-binary \@"+input_file_path+" -o "+ file_name +" localhost:30") But when trying it with subprocess.popen: Popen(['curl','--data-binary','\@'+input_file_path, '-o', file_name,'localhost:30'], stdout=PIPE).communicate()[0] Curl seems to hang up(logs into endless loop), ...

What permissions are required for subprocess.Popen?

The following code: gb = self.request.form['groupby'] typ = self.request.form['type'] tbl = self.request.form['table'] primary = self.request.form.get('primary', None) if primary is not None: create = False else: create = True mdb = tempfile.NamedTemporaryFile() mdb.write(self.request.form['mdb'].read()) mdb.seek(0) csv = tempfi...

Using popen() to invoke a shell command?

When running the following code through xcode I get inconsistent behavior. Sometimes it prints the git version correctly, other times it doesn't print anything. The return code from the shell command is always 0 though. Any ideas on why this might be? What am I doing wrong? #define BUFFER_SIZE 256 int main (int argc, const char * arg...

real time subprocess.Popen via stdout and PIPE

I am trying to grab stdout from a subprocess,Popen call and although I am achieving this easily by doing: cmd = subprocess.Popen('ls -l', shell=True, stdout=PIPE) for line in cmd.stdout.readlines(): print line I would like to grab stdout in "real time". With the above method, PIPE is waiting to grab all the stdout and then it retu...

Executing multiple commands using Popen.stdin

I'd like to execute multiple commands in a standalone application launched from a python script, using pipes. The only way I could reliably pass the commands to the stdin of the program was using Popen.communicate but it closes the program after the command gets executed. If I use Popen.stdin.write than the command executes only 1 time o...

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 ...

PHP popen and proc_open not returning binary output

When using popen or proc_open to run the following command to list the contents of a windows share: smbclient -N -U 'username%password' -O 'TCP_NODELAY IPTOS_LOWDELAY SO_KEEPALIVE SO_RCVBUF=8192 SO_SNDBUF=8192' -O 'TCP_NODELAY IPTOS_LOWDELAY SO_KEEPALIVE SO_RCVBUF=8192 SO_SNDBUF=8192' -d 0 '//server/sharename' -c 'dir "dirpath\*"' 2>/...

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...

Print out the output of os.popen() without buffering in python

Let's say that I have a process that prints out some data something like this ruby code. 1.upto(10) { |i| puts i puts "\n" sleep 0.6 } I want to have a python code that spawns this process, and read data from it to print it out. import os import sys cmd = "ruby /Users/smcho/Desktop/testit.rb"; pingaling = os.popen(...

reading a os.popen(command) into a string

I'm not to sure if my title is right. What I'm doing is writing a python script to automate some of my code writing. So I'm parsing through a .h file. but I want to expand all macros before I start. so I want to do a call to the shell to: gcc -E myHeader.h Which should out put the post preprocessed version of myHeader.h to stdout. Now...

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...

Discussion with a sub-process, using Ruby with IO and threading

Hi everyone, I am trying to use IO.popen in order to put (with .puts method) and to get (with .gets method) messages from a process to its sub-process. I am not very experimented and I have a question about. Having the following code, I have an error because it is not possible to write in a closed stream. class Interface def initia...

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...

How to supress Powershell window when using the -File option

I'm calling Powershell like so: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -noninteractive -nologo -file "C:\Users\dummy\Documents\dev\powershell\samples\test.ps1" I'm calling it from a python script, but the same problem can be observed if called via a shortcut. I thought the -NonInteractive flag would cause...

Django subprocess

I'm really sorry if this is a duplicate, but I have been searching, and haven't been able to find the answer. In Django I want to do something like (see the comments): # we have a file in our database... v = create_file_entry(clean_data, ip_address) # next, start a *background process* to upload the file somewhere else... p = Proce...

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...

Linux time sample based profiler.

short version: Is there a good time based sampling profiler for Linux? long version: I generally use OProfile to optimize my applications. I recently found a shortcoming that has me wondering. The problem was a tight loop spawning c++filt to demangle a c++ name. I only stumbled upon the code by accident while chasing down another b...