3

I have a python script that reads from standard in and performs some manipulation on it. The code runs and produces the expected output when invoked from my IDE where I pass in a text file as the standard input (using java's process builder fyiw).

When debugging with PDB and running the command in bash like so:

pythonTest.py < someText.txt

I get this error log:

/path/to/module/Test.py(46)<module>()
-> c = insertionSort(b)
(Pdb) *** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) *** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) *** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) *** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) *** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) 
Traceback (most recent call last):
  File "Test.py", line 46, in <module>
    c = insertionSort(b)
  File "Test.py", line 46, in <module>
    c = insertionSort(b)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/bdb.py", line 49, in trace_dispatch

I don't understand this log. It looks like another person had a similar error as me in this question but none of the answers helped me. Is there some reason why debugging script that takes standard in through redirection is problematic?

Community
  • 1
  • 1
Alex Bollbach
  • 4,370
  • 9
  • 32
  • 80
  • 1
    [This answer](http://stackoverflow.com/a/34687825/3366578) from the question you've mentioned worked for me. I'd try to explain but It's been already done [here](http://stackoverflow.com/questions/9178751/use-pdb-set-trace-in-a-script-that-reads-stdin-via-a-pipe#comment62352104_34687825). You could try to write a small piece of code that reproduces the problem and share it here, so we could try it out. – fscherrer Nov 04 '16 at 22:52

0 Answers0