I’m trying to run the following little Python script:
#!/usr/local/bin/python2.5
import sys, subprocess
child = subprocess.Popen("muscle -stable -FASTA",
stdin=sys.stdin,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=(sys.platform!="win32"))
print child.stderr.read()
print child.stdout.read()
Which works fine if stdin does not exceed about 3750 characters. Above this limit, the subprocess does no longer produce any stdout or stderr. If I switch them for sys.stdout and sys.stderr respectively, everything works again as expected. The muscle executable writes to both stdout and stderr when called from command-line.
Any suggestions what could be the cause and how to solve this?- best without updating Python, since the installation is on a server I have limited access to.
Use
child.communicate(someinput)to get the full output; see the ‘warning’ boxes in the documentation also. If you really need to read stdin interactively while writing to stdout, then (at least on Windows) you may be out of luck with Python + pipes.