How is pdb Python code with input?

I am debugging Python code using pdb. The code is needed for input from stdin, for example:

python -m pdb foo.py < bar.in 

Then pdb will accept the bar.in command as commands. How to tell pdb that the input is for foo.py and not for pdb?

+6
python
source share
2 answers

Well, that’s a subtle reaction to Aaron’s answer, but I don’t think he understands what you want to interactively debug at some point, right? This works, but the program exits before you get the opportunity to debug.

 (echo cont;cat bar.in) | python -m pdb foo.py 

I think if you can edit foo.py do import pdb and then at foo.py point of interest do pdb.set_trace() and just run python foo.py without -m pdb and give it bar.in usually

 python foo.py < bar.in 
+3
source share

At the beginning of bar.in , put cont :

 cont one two three four aaron@ares ~$ python -m pdb cat.py < bar.in > ~/cat.py(1)<module>() -> import sys (Pdb) one two three four The program finished and will be restarted > ~/cat.py(1)<module>() -> import sys (Pdb) 
+1
source share

All Articles