[Tutor] piping to system commands
Gabriel Farrell
gsf at panix.com
Thu Jul 13 21:47:12 CEST 2006
I'm trying to create a master dictionary in aspell, and I can do so
with the following:
inFile = tempfile.NamedTemporaryFile()
inFile.write(wordList)
inFile.flush()
command = 'aspell --lang=en --dont-validate-words create master %s < %s' % \
('./dict.cwl', inFile.name)
os.system(command)
or, in 2.4, instead of os.system(command):
retcode = subprocess.call(command, shell = True)
I'm wondering, is there a way to do this more directly, without the
need for a temp file, and in a way where I the stdout coming from
aspell won't go to sys.stdout? The following seems to work, but the
end of the input gets cut off.
command = 'aspell --lang=en --dont-validate-words create master ./dict.cwl'
pipe = subprocess.Popen(command, stdin = subprocess.PIPE, shell=True).stdin
pipe.write()
pipe.flush()
pipe.close()
gsf
More information about the Tutor
mailing list