Using input redirection command ("<") in IPython
Question: In windows command line, I am using the [redirection operator
("<")](https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-
us/redirection.mspx?mfr=true) to read input from a file. To run my python
module, I would do something like:

`python myscript.py <input.txt`

In `myscript.py`, I am using `sys.stdin.readline()` to read the input stream,
something like:

    
    
    def main(argv):
        line = sys.stdin.readline() 
        while line:
            doSomething()
            line = sys.stdin.readline()
    
    if __name__ == "__main__": 
        main(sys.argv)
    

This works find on the command line.

Is there a way to use the redirection command in IPython? I want to debug the
file. Thanks.

I am running Python 3.5.1:: Anaconda 2.5.0 on Win64.


Answer: Not easily. The redirection is a feature of the host command shell, and
running anything inside IPython will isolate you from that.

Another way to do what you're looking for is to bring IPython into your
program. If you know the place where it is breaking, you can add the following
code to the except block of a try-except around the broken line:

    
    
    import IPython
    IPython.embed()
    

This will start an interactive IPython shell in the context the error
occurred.

Alternatively, you can run the program under the control of the debugger:
[Step-by-step debugging with
IPython](http://stackoverflow.com/questions/16867347/step-by-step-debugging-
with-ipython)

