Search code examples
pythonsubprocessstdinpopeneof

How to send STDIN twice to Popen process, each time with EOF?


I have this part of a code:

for stdin in stdins:
    p.stdin.write(stdin)

which writes string stdin to process p's STDIN.

The challenge is: the process p expects to see EOF before it goes to next STDIN.

With the loop above, the problem is that subsequent p.stdin.write(stdin) will be considered by the process p as input of the 1st STDIN input collection. Because, as said earlier, p expect to see an EOF before moving to subsequent fields.

So, my question is: how to solve this problem in Python? The process needs to see something like:

for stdin in stdins:
    p.stdin.write(stdin)
    p.stdin.send_eof()

Constraints: solution must not use pexpect.


Solution

  • EOF is not a character, it just means there is no more data to read.

    As such I don't believe what you're after is possible in Python or most other languages.