P
P
Philip Polikarenkov2016-02-08 16:04:00
Python
Philip Polikarenkov, 2016-02-08 16:04:00

Is it possible to intercept command line output in real time?

Good afternoon, OS - windows 7.
I am writing a simple program for myself, in which the archiver (winrar) is launched via the command line (via the subprocess module), extracts files and closes. Winrar sends the extraction progress to the console, can I intercept it in real time and bind it to a variable?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andy_U, 2016-02-08
@Vilibb

This solution is much prettier. Naturally, some refinement with a file of the SubprocessProtocol class will be required. I recently checked - it works, and you can simultaneously intercept both stdout and stderr.
PS Just in case, the data parameter in pipe_data_received is bytes, so it needs to be decoded into a utf-8 string. If under Windows there are Russian file names, you will have to figure out what encoding rar uses. Most likely - cp866.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question