subprocess woes

km srikrishnamohan at gmail.com
Tue Aug 29 08:47:47 EDT 2006


Hi all,

I have a strange question.
a program on shell looks as follows:
$cat test.fa |fasta34 -q @ s
where test.fa contains a protein sequence (alphabets); s is the
database to be searched and @
+indicates that the input is from stdin (ie., 'cat test.fa')
now instead of 'cat test.fa' i take that input into a varaible  and
want to feed it to the
+program.
I have  a sequence string in a variable named x, and use subprocess
module to wrap this:
######code start ######
import subprocess as sp
x = 'GSQIPSHYWKKNLWYYSHEIDGGCHNMW'
p0 = sp.Popen(["echo",x], stdout=sp.PIPE)
p1 = sp.Popen(["fasta34","-q","@",s],stdin=p0.stdout, stdout=sp.PIPE)
output = p1.communicate()[0]
print output
########code end#####

Output for this code doesnt give me the result as the program senses
the input as empty
let me know  where i am wrong.

The idea is to pipe-input the string to the program as a variable as
mentioned above.

regards,
KM



More information about the Python-list mailing list