How to get output from subprocess.Popen(). proc.stdout.readline() blocks, no data prints out

You obviously can use subprocess.communicate but I think you are looking for real time input and output. readline was blocked because the process is probably waiting on your input. You can read character by character to overcome this like the following: import subprocess import sys process = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) while True: out … Read more

How can I specify working directory for a subprocess

subprocess.Popen takes a cwd argument to set the Current Working Directory; you’ll also want to escape your backslashes (‘d:\\test\\local’), or use r’d:\test\local’ so that the backslashes aren’t interpreted as escape sequences by Python. The way you have it written, the \t part will be translated to a tab. So, your new line should look like: … Read more

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

Update with code that appears not to work (on windows anyway) class ThreadWorker(threading.Thread): def __init__(self, callable, *args, **kwargs): super(ThreadWorker, self).__init__() self.callable = callable self.args = args self.kwargs = kwargs self.setDaemon(True) def run(self): try: self.callable(*self.args, **self.kwargs) except wx.PyDeadObjectError: pass except Exception, e: print e if __name__ == “__main__”: import os from subprocess import Popen, PIPE def … Read more

How to write to stdout AND to log file simultaneously with Popen?

You can use a pipe to read the data from the program’s stdout and write it to all the places you want: import sys import subprocess logfile = open(‘logfile’, ‘w’) proc=subprocess.Popen([‘cat’, ‘file’], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) for line in proc.stdout: sys.stdout.write(line) logfile.write(line) proc.wait() UPDATE In python 3, the universal_newlines parameter controls how pipes are used. If False, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)