Jun-27-2018, 05:59 AM
(Jun-26-2018, 01:17 PM)volcano63 Wrote: Cannot be done, you say ? This was done on Ubuntu
I redirect
Output:In [23]: ping_proc = subprocess.Popen(['ping', 'google.com'], ...: stdout=subprocess.PIPE, stdin=subprocess.PIPE, ...: stderr=subprocess.STDOUT, universal_newlines=True) In [24]: for line_no, line in enumerate(ping_proc.stdout): ...: print(line,) ...: if line_no == 10: ...: print('Killing process') ...: ping_proc.kill() ...: break ...: 64 bytes from lhr25s10-in-f14.1e100.net (216.58.198.174): icmp_seq=3 ttl=50 time=66.0 ms 64 bytes from lhr25s10-in-f14.1e100.net (216.58.198.174): icmp_seq=4 ttl=50 time=66.1 ms 64 bytes from lhr25s10-in-f14.1e100.net (216.58.198.174): icmp_seq=5 ttl=50 time=66.3 ms 64 bytes from lhr25s10-in-f14.1e100.net (216.58.198.174): icmp_seq=6 ttl=50 time=66.0 ms 64 bytes from lhr25s10-in-f14.1e100.net (216.58.198.174): icmp_seq=7 ttl=50 time=66.2 ms 64 bytes from lhr25s10-in-f14.1e100.net (216.58.198.174): icmp_seq=8 ttl=50 time=66.1 ms 64 bytes from lhr25s10-in-f14.1e100.net (216.58.198.174): icmp_seq=9 ttl=50 time=66.1 ms 64 bytes from lhr25s10-in-f14.1e100.net (216.58.198.174): icmp_seq=10 ttl=50 time=66.2 ms Killing processstderr
tostdout
- some processes usestderr
instead ofstdout
, so suppressing the former is a bad idea
Interesting! That is golden advice even if it does not work..
The ping example works fine with stdout but not the tool in question.
I am not at my computer until this evening and I will try it then but that is certainly something I have not tried as of yet!
I must stress that it is a windows CLI Tool but the beauty of subprocess is that it is cross platform.
Is there anything to consider if its windows?