2012-01-03 244 views

回答

4

您正在寻找subprocess.Popen()而不是call()。您还需要将其更改为p2.communicate()[0]

3

这是因为subprocess.call返回一个int:

subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False) 

    Run the command described by args. Wait for command to complete, then return the returncode attribute. 

它看起来像你想subprocess.Popen().

下面是一段典型的代码一块,我必须这样做:

p = Popen(cmd, stdout=PIPE, stderr=PIPE, bufsize=256*1024*1024) 
output, errors = p.communicate() 
if p.returncode: 
    raise Exception(errors) 
else: 
    # Print stdout from cmd call 
    print output 
0

您应该使用子过程

try:    
     subprocess.check_output(['./test.out', 'new_file.mfj', 'delete1.out'], shell=True, stderr=subprocess.STDOUT) 
    except subprocess.CalledProcessError as exception: 
     print exception.output