How to debug python CLI that takes stdin?

前端 未结 4 831
悲&欢浪女
悲&欢浪女 2020-12-28 14:08

I\'m trying to debug a Python CLI I wrote that can take its arguments from stdin. A simple test case would have the output of

echo \"test\" | python mytool.p         


        
4条回答
  •  无人及你
    2020-12-28 15:02

    When you use pdb(or any other python debugger) it acquires stdin for debug commands, that's why you get NameError: name 'test' is not defined.

    For example this command will quit debugger at the begging of a runtime and you wont get this error(nor interactive debugging) for one run:

    (echo cont;echo "test") | python -m pdb mytool.py

提交回复
热议问题