Raising exception on STDIN read
Michael Goerz
newsgroup898sfie at 8439.e4ward.com
Wed Feb 27 17:06:00 EST 2008
Grant Edwards wrote, on 02/27/2008 04:34 PM:
> 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?
>
> If I were you, I'd just run LaTeX in batch mode. That's what I
> always used to do when automating the running of LaTeX using a
> shell script or makefile. IIRC, you do something like this:
>
> ret = os.system("latex \\batchmode\\input %s" % filename)
Yeah, I'm doing that by default. The problem in my actual program is
that the user can change the latex command and the compiler options, so
I can't guarantee that the latex compiler is being run in batchmode or
nonstopmode (The user might screw up). So, ideally, I want to enforce
that the subprocess is non-interactive by trowing an exception if it
does ask for input.
I have to use subprocess instead of os.system because I want to filter
the output (colorize it, parse for warnings, etc.)
Thanks,
Michael
More information about the Python-list
mailing list