Jun-21-2019, 07:01 PM
Have you looked at doc?
See parameter
Work in
See parameter
encoding=None
setting to encoding='utf-8'
stdout will by string(Unicode default) Python 3.Work in
run()
to which should be used in all cases it can handle.subprocess.run() Wrote:The recommended approach to invoking subprocesses is to use therun()
function for all use cases it can handle.
For more advanced use cases, the underlying Popen interface can be used directly.
import subprocess output = subprocess.run(['ping', '-n', '4', 'google.com'], encoding='utf-8', capture_output=True) print(output.stdout)
Output:Pinging google.com [2a00:1450:400f:80b::200e] with 32 bytes of data:
Reply from 2a00:1450:400f:80b::200e: time=42ms
Reply from 2a00:1450:400f:80b::200e: time=33ms
Reply from 2a00:1450:400f:80b::200e: time=46ms
Reply from 2a00:1450:400f:80b::200e: time=50ms
Ping statistics for 2a00:1450:400f:80b::200e:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 33ms, Maximum = 50ms, Average = 42ms