subprocess

Why does this code behave differently in Python3.1 than in Python2.6?

I'm very new to programming so I apologize in advance if my question is too silly. #!/usr/bin/python2.6 import subprocess, time p=subprocess.Popen(['cat'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) for i in 'abcd': p.stdin.write(str.encode(i+'\n')) output=p.stdout.readline() print(output) time.sleep(1...

howto scroll a gtk.scrolledwindow object from python code

I'm writing a python application that has a glade gui. Using subprocess to execute some shell commands in the background. Using a glade GUI which has a scrolledwindow widget and a textview widget inside the scrolledwindow widget. The textview gets populated as the subprocess.Popen object run and display their stdout and stderr to this t...

anyone have example python code that sends mail using sendmail and subprocess?

I'm kind of confused about how subprocess.Popen works. If anyone has example code that sends email using the subprocess module and sendmail that'd be great. ...

twisted threading with subprocess.Popen?

I'm trying to implement a service with Twisted that's fairly close to the "finger" tutorial found here: http://twistedmatrix.com/documents/current/core/howto/tutorial/intro.html I've got a basic.LineListener waiting for a command and then executing it, then I have a client connecting and issuing commands. Trouble is that the command som...

Start and capture GUI's output from same Python script and transfer variables?

Hi, I have to start a GUI from an existing Python application. The GUI is actually separate Python GUI that can run alone. Right now, I am starting the GUI using something like: res=Popen(['c:\python26\pythonw.exe', full_filename, str(RESULTs), str(context)], stdout=PI...

What causes subprocess.call to output blank file when attempting db export with mysqldump?

I am having some problems using subprocess.call to export a database using mysqldump. I'm using Python 3.1 installed on Windows 7. from time import gmtime, strftime import subprocess DumpDir = "c:/apps/sqlbackup/"; DumpFile = "mysqldump-" + strftime("%Y-%m-%d-%H-%M-%S", gmtime()) + ".sql"; params = [r"mysqldump --user root --password=...

Retrieving the output of subprocess.call()

How can I get the output of a process run using subprocess.call()? Passing a StringIO.StringIO object to stdout gives this error: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 444, in call return Popen(*popenargs,...

How do I send a mail via mailx & subprcoess?

Hello all. I am EE, trying to write a script to simplify file checks using Python. For some reason, our IT will not let me gain access to our smtp server, and will only allow sending mail via mailx. So, I've thought of running mailx from Python and send it, in the same way that it works in my console. Alas, it gives an exeption. See Lin...

How to diff file and output stream "on-the-fly"?

I need to create a diff file using standard UNIX diff command with python subprocess module. The problem is that I must compare file and stream without creating tempopary file. I thought about using named pipes via os.mkfifo method, but didn't reach any good result. Please, can you write a simple example on how to solve this stuff? I tri...

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

Launching Java Subprocess using parent process Classpath

I want to launch a java subprocess, with the same java classpath and dynamically loaded classes as the current java process. The following is not enough, because it doesn't include any dynamically loaded classes: String classpath = System.getProperty("java.class.path"); Currently I'm searching for each needed class with the code below...

Grabbing the output of MAPLE via Python

How would I use the subprocess module in Python to start a command line instance of MAPLE to feed and return output to the main code? For example I'd like: X = '1+1;' print MAPLE(X) To return the value of "2". The best I've seen is a SAGE wrapper around the MAPLE commands, but I'd like to not install and use the overhead of SAGE for ...

Using wget with subprocess

Hi! I'm trying to use wget with subprocess. my attempts worked until I tried to download the page to a specified directory with this code: url = 'google.com' location = '/home/patrick/downloads' args = ['wget', 'r', 'l 1' 'p' 'P %s' % location, url] output = Popen(args, stdout=PIPE) if I run this code in /home/patrick I get index.ht...

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

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

How to make os.mkfifo and subprocess.Popen work together?

I'm trying to redirect a patch command output using a named pipe. I tried like this: fifo = os.path.join(self.path, 'pipe') os.mkfifo(fifo) op = os.popen('cat '+ fifo) proc = Popen(['patch', current_keyframe, '--input='+fpath, '--output='+fifo], stdin=PIPE, stdout=PIPE) os.unlink(fifo) print op.read() But my script stops at Popen() ca...

why this dos command does not work inside python?

I try to move some dos command from my batch file into python but get this error, The filename, directory name, or volume label syntax is incorrect, for the following statement. subprocess.Popen('rd /s /q .\ProcessControlSimulator\bin', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if I just copy tha...

python subprocess communicate() block

i am using subprocess to call a external program plink.exe to login to a server, but when i call communicate to read the output, it blocking. the code is below: import subprocess process = subprocess.Popen('plink.exe [email protected] -pw 123456'.split(), shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) print process....

Python's subprocess.Popen object hangs gathering child output when child process does not exit

When a process exits abnormally or not at all, I still want to be able to gather what output it may have generated up until that point. The obvious solution to this example code is to kill the child process with an os.kill, but in my real code, the child is hung waiting for NFS and does not respond to a SIGKILL. #!/usr/bin/python impor...

How to redirect stdout for a subprocess?

def StartProc(dir, parm): global proc proc_log = open(dir + os.sep + "MyLog.txt","w") #new path for each file if parm: proc = subprocess.Popen(path, 0, None, subprocess.PIPE, proc_log, None) else: MyReset(proc) #reset the process(proc) to its default values proc.stdout = ...