I am writing a Python shell script (childscript.py) for a command line executable (childprogram). Another executable (parentprogram) spawns childscript.py and outputs it to childscript.py. childscript.py creates a child program with:
retval = subprocess.Popen(RUNLINE, shell=False, stdout=None, stderr=None, stdin=subprocess.PIPE)
If childscript.py does a series of readings from sys.stdin directly using readline:
line = sys.stdin.readline()
I can get all the output from the parent program and pass it to the childprogram.
However, if I try to use the codec module by doing:
sys.stdin = codecs.open(sys.stdin.fileno(), encoding='iso-8859-1', mode='rb', buffering=0)
or execute:
sys.stdin = codecs.getreader('iso-8859-1')(sys.stdin.detach())
, . , , . , childscript.py , , .
- ? childscript.py iso-8859-1 .
EDIT:
, Python v3.x "open" . , "open" "codecs.open":
sys.stdin = open(sys.stdin.fileno(), encoding='iso-8859-1', mode='r')
, - , open.codecs. script "open" .
- , -, .