[Tutor] write to /dev/stdin during call to posix command?

Jeff Kowalczyk jtk at yahoo.com
Fri Sep 10 19:16:07 CEST 2004


How can I write to /dev/stdin during a call to a posix command? The
pdftotext command will write to stdout if given '-' as the output
filename, but it lacks the same paramater for reading from stdin.

However, using /dev/stdin and directing a file to the input works fine:

# pdftotext -layout /dev/stdin - < sample.pdf

Reading from stdout with a physical file input is no problem:

r,w,e = os.popen3('pdftotext -layout sample.pdf -')
w.read()   # gives the text string I am looking for

But I don't quite understand how I should send a string representing the
input pdf (pdfinput) to the version of the command using /dev/stdin:

pdfinput = open('sample.pdf','r').read()
r,w,e = os.popen3('pdftotext -layout /dev/stdin -')

Any ideas? I'm using python-2.3.4, linux. Thanks.

Jeff



More information about the Tutor mailing list