-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://reviewboard-fedoraserver.rhcloud.com/r/127/#review378
-----------------------------------------------------------
I tried to use the code with a small bash script that is simply writing the strings read
from stdin to a log file. The call to the script with writing several lines to it does not
return before I press Ctrl-D in the term calling the python scriptlet. Additionally there
is no output in the log file.
Here is the test code:
import os
import pwd
import subprocess
from rolekit.functions import writefile
from tempfile import SpooledTemporaryFile
def temporary_stdin(io_input):
"""
Create a temporary in-memory file object to store input for
subprocess_future() calls. This is useful for passing passwords
without specifying them on the command line (which would cause
them to appear in the process table)
"""
f = SpooledTemporaryFile()
f.write(io_input)
f.seek(0)
writefile("/tmp/readstdin", '#!/bin/bash\nwhile read line\ndo\necho
"$line" >> /tmp/readstdin.log\ndone\n')
stdinfile = temporary_stdin("line 1\nline 2\nline 3\n")
preexec_fn = None
args = [ "/bin/bash", "/tmp/readstdin" ]
try:
process = subprocess.Popen(args, close_fds=True,
stdin=stdinfile,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
preexec_fn=preexec_fn)
except OSError, e:
if e.errno is errno.EPERM:
# Could not change users prior to executing the subprocess
print("ERROR: Insufficient privileges to impersonate UID/GID %s/%s" %
(uid, gid))
raise
print process.stdout.read()
- Thomas Woerner
On Jan. 22, 2015, 10 p.m., Stephen Gallagher wrote:
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://reviewboard-fedoraserver.rhcloud.com/r/127/
-----------------------------------------------------------
(Updated Jan. 22, 2015, 10 p.m.)
Review request for RoleKit Mailing List, Miloslav Trmac, Stephen Gallagher, and Thomas
Woerner.
Repository: rolekit
Description
-------
Add utility routine for passing stdin into subprocesses
Diffs
-----
src/rolekit/async.py 0f9ddaac1beb27cebdf41ca0383a62a807c4fcb6
src/rolekit/util.py f3825d748475ea837e84004129459083269d9686
Diff:
http://reviewboard-fedoraserver.rhcloud.com/r/127/diff/
Testing
-------
Thanks,
Stephen Gallagher