Skip to content
Advertisement

Strip positional information from subprocess std out

I am running a subprocess in python, capturing the std output:

JavaScript

The command in question uses positional characters to update the number of packets sent, but in the resultant output, eg results.stdout, I see all of the updates.

JavaScript

Ideally, I only want to save the final output, eg

JavaScript

Not every one of the 194 interim lines. Is there a way do decode the stdout to only show the final string?

Advertisement

Answer

x1b[2K is the signal to erase the entire line. So this will get you the final thing printed:

JavaScript

That still leave the other ANSI codes, but since this uses a fixed set, those should be easy to remove.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement