|
From: <di...@us...> - 2010-11-19 14:41:10
|
Revision: 686
http://safekeep.svn.sourceforge.net/safekeep/?rev=686&view=rev
Author: dimi
Date: 2010-11-19 14:41:04 +0000 (Fri, 19 Nov 2010)
Log Message:
-----------
Add ability to capture the output of a spawned proccess
Modified Paths:
--------------
safekeep/trunk/safekeep
Modified: safekeep/trunk/safekeep
===================================================================
--- safekeep/trunk/safekeep 2010-11-19 08:57:27 UTC (rev 685)
+++ safekeep/trunk/safekeep 2010-11-19 14:41:04 UTC (rev 686)
@@ -112,7 +112,7 @@
else:
return args
-def do_spawn(args, shell=False):
+def do_spawn(args, shell=False, stdout=False):
global cmd
argslist = args_to_list(args)
cmd = argslist[0]
@@ -125,15 +125,19 @@
debug('Run [' + ' '.join(argslist) + ']')
proc = subprocess.Popen(argslist, bufsize=1, shell=False, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
proc.stdin.close()
+ lines=[]
for line in proc.stdout:
- info(line.rstrip())
+ if stdout:
+ lines.append(line)
+ else:
+ info(line.rstrip())
proc.stdout.close()
- return proc.wait()
+ return (proc.wait(), ''.join(lines))
def spawn(args, shell=False):
global cmd
try:
- rc = do_spawn(args, shell=shell)
+ rc, out = do_spawn(args, shell=shell)
except OSError, ex:
error("OSError: %s: %s" % (cmd, ex))
@@ -151,7 +155,7 @@
def try_to_run(args):
try:
- rc = do_spawn(args)
+ rc, out = do_spawn(args)
except OSError, ex:
return False
return rc in (0,1)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|