i need to read the data as it arrives, hence the need for the pipe. it had previously written the data to a temporary file and read the file and that got str from read, but now i need to read from a pipe, and now i get bytes. i will look at another possible design, but i do want to solve this with Popen(). on your ping command test, try doing it without the option
-n 4
on the command and get your pings out as they arrive.
i just did try
run()
and it looks like (from the trace dump) that it calls
Popen()
itself, passing all the keyword options. my documentation does not show an
encoding=
option for either
run()
or
Popen()
.
Output:
Traceback (most recent call last):
File "test1.py", line 10, in <module>
out = run(['aws','s3','ls'],encoding='utf-8',capture_output=True)
File "/usr/lib/python3.5/subprocess.py", line 693, in run
with Popen(*popenargs, **kwargs) as process:
TypeError: __init__() got an unexpected keyword argument 'encoding'
from the source code:
Output:
lt2a/forums /home/forums 8> cat -n /usr/lib/python3.5/subprocess.py|lines 830 874
830 class Popen(object):
831
832 _child_created = False # Set here since __del__ checks it
833
834 def __init__(self, args, bufsize=-1, executable=None,
835 stdin=None, stdout=None, stderr=None,
836 preexec_fn=None, close_fds=_PLATFORM_DEFAULT_CLOSE_FDS,
837 shell=False, cwd=None, env=None, universal_newlines=False,
838 startupinfo=None, creationflags=0,
839 restore_signals=True, start_new_session=False,
840 pass_fds=()):
841 """Create new Popen instance."""
842 _cleanup()
843 # Held while anything is calling waitpid before returncode has been
844 # updated to prevent clobbering returncode if wait() or poll() are
845 # called from multiple threads at once. After acquiring the lock,
846 # code must re-check self.returncode to see if another thread just
847 # finished a waitpid() call.
848 self._waitpid_lock = threading.Lock()
849
850 self._input = None
851 self._communication_started = False
852 if bufsize is None:
853 bufsize = -1 # Restore default
854 if not isinstance(bufsize, int):
855 raise TypeError("bufsize must be an integer")
856
857 if _mswindows:
858 if preexec_fn is not None:
859 raise ValueError("preexec_fn is not supported on Windows "
860 "platforms")
861 any_stdio_set = (stdin is not None or stdout is not None or
862 stderr is not None)
863 if close_fds is _PLATFORM_DEFAULT_CLOSE_FDS:
864 if any_stdio_set:
865 close_fds = False
866 else:
867 close_fds = True
868 elif close_fds and any_stdio_set:
869 raise ValueError(
870 "close_fds is not supported on Windows platforms"
871 " if you redirect stdin/stdout/stderr")
872 else:
873 # POSIX
lt2a/forums /home/forums 9>