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
You can use another file descriptor. With bash you can create a new file descriptor with:
exec 3<> test.txt
And then on your python file have something like:
#!/usr/bin/python
# Use fd 3 as another stdin file.
import os
stdin=os.fdopen(3)
while True:
s=stdin.readline()
import pdb; pdb.set_trace()
print len(s)
Just runing your script will use that test.txt as input, and you can use stdin on stdin. It can be used as well with pipes if you need.