rockindy wrote: ↑
Tue Apr 28, 2020 3:05 am
And I don't know how to tell the redirection is from '<' or from Popen.
Why would you need to?
My suggestion is once you set -i flag, it will always call do_repl().
That much is common between dhylands’ solution and yours. What’s different is what happens when you don’t set the -i flag.
And if you want to run script from a file, just use '<' without -i flag.
That’s what works in dhylands’ solution but not in yours.
(At least that’s my understanding just from reading the code, I haven’t actually tested it.)
(You may be talking past each other with respect to whether you are talking about “micropython script.py < inputfile” or “micropython < script.py”.)