safepopen: add support for optional stdin oneshot buffer

This commit is contained in:
Oleksii Shevchuk 2019-03-10 23:39:13 +02:00
parent 5e93c40751
commit c61c6f74c7
1 changed files with 5 additions and 0 deletions

View File

@ -88,6 +88,7 @@ class SafePopen(object):
def __init__(self, *popen_args, **popen_kwargs):
self._popen_args = popen_args
self._interactive = popen_kwargs.pop('interactive', False)
self._stdin_data = popen_kwargs.pop('stdin_data', None)
self._suid = popen_kwargs.pop('suid', None)
if not ON_POSIX:
@ -139,6 +140,10 @@ class SafePopen(object):
**kwargs
)
if self._stdin_data:
self._pipe.stdin.write(self._stdin_data)
self._pipe.stdin.flush()
if not self._interactive:
self._pipe.stdin.close()