Raising exception on STDIN read
Michael Goerz
newsgroup898sfie at 8439.e4ward.com
Wed Feb 27 15:59:59 EST 2008
Gabriel Genellina wrote, on 02/27/2008 03:26 PM:
> En Wed, 27 Feb 2008 15:06:36 -0200, Ian Clark <iclark at mail.ewu.edu>
> escribi�:
>
>> On 2008-02-27, Michael Goerz <newsgroup898sfie at 8439.e4ward.com> wrote:
>>> Hi,
>>>
>>> I would like to raise an exception any time a subprocess tries to read
>>> from STDIN:
>>>
>>> latexprocess = subprocess.Popen( \
>>> 'pdflatex' + " " \
>>> + 'test' + " 2>&1", \
>>> shell=True, \
>>> cwd=os.getcwd(), \
>>> env=os.environ, \
>>> stdin=StdinCatcher() # any ideas here?
>>> )
>>>
>>> An exception should be raised whenever the pdflatex process
>>> reads from STDIN... and I have no idea how to do it. Any suggestions?
>
>> How about with a file-like object? I haven't tested this with subprocess
>> so you might want to read the manual on files if it doesn't work[1].
>
> Won't work for an external process, as pdflatex (and the OS) knows
> nothing about Python objects. The arguments to subprocess.Popen must be
> actual files having real OS file descriptors.
>
> Try with stdin=open("/dev/full") or stdin=open("/dev/null")
using /dev/null works in my specific case (in my posted minimal example
I still have to press Enter, but in the real program it causes pdflatex
to fail, like I want it to). However, the solution is limited do Linux,
as on Windows there's no /dev/null. Is there a platform independent
solution?
Michael
More information about the Python-list
mailing list