Ned Deily added the comment:
The problem here is that you are trying to use sys.stdin for two different
purposes: 1. as a data input source for your program using stdin redirected to
a disk file; and 2. for pdb's source of debugging commands, expected to be a
terminal file. By specifying "-m pdb", you are telling pdb to start an
interactive debugging which it does, paused at the first statement in sample.py
("-> import sys, pdb"). It (actually the cmd standard library module which pdb
uses) then tries to read stdin for command input but, because of the command
line redirect (" < binary.exe"), reads the binary file instead. Note this
happens before sample.py has done anything. If you just ran the command
"python sample.py < binary.exe", then pdb would not be involved initially, the
script would run, read the redirected file until EOF, and then invoke pdb via
set_trace. But, at that point, the redirected sys.stdin is at EOF so pdb
immediately exits after trying to read a command. The doc page for pdb does no
t specifically warn against redirecting stdin but it does document that the
pdb.Pdb instance passes stdin arguments to a cmd.Cmd instance which defaults to
using sys.stdin. I think that's warning enough.
There is an open pdb feature request, Issue20061, to make it more convenient to
use pdb with a separate terminal window. That feature would also cover the
rare use case here of having a redirected stdin with pdb. Otherwise, you need
to be careful how you use stdin while using pdb.
----------
components: +Library (Lib) -Windows
nosy: +ned.deily
resolution: -> not a bug
stage: -> resolved
status: open -> closed
type: crash ->
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue22009>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com