subprocess woes
Simon Forman
rogue_pedro at yahoo.com
Tue Aug 29 20:48:01 EDT 2006
Dennis Lee Bieber wrote:
> On Tue, 29 Aug 2006 18:17:47 +0530, km <srikrishnamohan at gmail.com>
> declaimed the following in comp.lang.python:
>
> > ######code start ######
> > import subprocess as sp
> > x = 'GSQIPSHYWKKNLWYYSHEIDGGCHNMW'
> > p0 = sp.Popen(["echo",x], stdout=sp.PIPE)
>
> Why use this at all?
>
> > p1 = sp.Popen(["fasta34","-q","@",s],stdin=p0.stdout, stdout=sp.PIPE)
> > output = p1.communicate()[0]
>
> Just feed "x" to this directly... (untested):
>
> p1 = sp.Popen(["fasta34","-q","@",s],stdin=sp.PIPE, stdout=sp.PIPE)
> output = p1.communicate(x)[0]
> --
> Wulfraed Dennis Lee Bieber KD6MOG
> wlfraed at ix.netcom.com wulfraed at bestiaria.com
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff: web-asst at bestiaria.com)
> HTTP://www.bestiaria.com/
You can also pass data to a subprocess like this:
p1 = sp.Popen(["fasta34","-q","@",s],stdin=sp.PIPE, stdout=sp.PIPE)
p1.stdin.write(x)
p1.stdin.close()
But I think communicate() would be better for you in this case.
Peace,
~Simon
More information about the Python-list
mailing list