[Biopython] subprocess.Popen problem
Mic
mictadlo at gmail.com
Tue Jan 3 02:05:48 UTC 2012
With the following code:
if __name__ == '__main__':
cmd_soap = 'soap ...'
proc = subprocess.Popen(cmd_soap, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
returncode = proc.wait()
print "returncoded", returncode
stdout_value, stderr_value = proc.communicate()
print 'stderr ', stderr_value
for line in stderr_value:
print "!", line
if returncode == 1:
sys.exit(1)
I get this:
! B
! e
! g
! i
! n
!
! P
! r
! o
! g
! r
! a
! m
!
! S
! O
! A
! P
! a
! l
! i
! g
! n
! e
! r
! /
! s
! o
! a
! p
! 2
!
...
instead of :
Begin Program SOAPaligner/soap2
...
What did I wrong?
On Thu, Nov 3, 2011 at 7:31 PM, Peter Cock <p.j.a.cock at googlemail.com>wrote:
> On Thu, Nov 3, 2011 at 3:16 AM, Mic <mictadlo at gmail.com> wrote:
> > Thank you, I wrote the following code and not sure whether it is what did
> > write me.
>
> Depending on the tool I would check for a non-zero return code rather
> than just treating 1 as an error.
>
> You are also not collecting stderr/stdout correctly. If you send them
> to a pipe, the strings from the .communicate will be empty. Rather
> reads from the process object's .stdout and .stderr handles. See:
> http://docs.python.org/library/subprocess.html
>
> Peter
>
More information about the Biopython
mailing list