osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

running "python -i" in subprocess shows no prompt


Hello,
I try to start a separate python subprocess using the attached code. This example should catch all stdout and stderr output from the launched subprocess and send commands to its stdin.
The problem is that the prompt ">>>" asking for then next input is neither sent to stdout nor to stderr. The commands sent to stdin aren't echoed to stdout either.
 The output from the attached code looks as follows:
'''
Python 2.7.13 (default, Nov 23 2017, 15:37:09)
[GCC 6.3.0 20170406] on linux2
Type "help", "copyright", "credits" or "license" for more information.
1
4
9
16
'''

I am expecting to get the same output as if I sent the same input to a standalone interactive python interpreter, which would be this:
'''
Python 2.7.13 (default, Nov 23 2017, 15:37:09)
[GCC 6.3.0 20170406] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 1*1
1
>>> 2*2
4
>>> 3*3
9
>>> 4*4
16
>>>
'''

I cannot simple print the ">>>" after each readline(), because I don't know how much output will follow before the next input prompt is required.
What needs to be changed in my code to make the subprocess forward the missing parts to the output pipes?

regards
Finn