1

I'm trying to get the output of a traceroute using subroutine.check_output, but there's always a line "traceroute to twitter.com (104.244.42.193), 64 hops max, 52 byte packets" that prints in the terminal is is excluded from the output in my script. Any way to get around this while still using subroutine.check_output?

1 Answers1

0

That's because this line is printed on standard error stream.

To merge both stdout and stderr:

p = subprocess.check_output(command,stderr=subprocess.STDOUT)

extract from help(subprocess.check_output)

To capture standard error in the result, use stderr=STDOUT.

>>> check_output(["/bin/sh", "-c",
...               "ls -l non_existent_file ; exit 0"],
...              stderr=STDOUT)
b'ls: non_existent_file: No such file or directory\n'
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219