I want to redirect the output of subprocess.call(...)
to a xz- or bzip2-compressed file.
I tried :
with lzma.open(log_path, "x") as log_file:
subprocess.call(command, stdout=log_file, stderr=log_file)
but the resulting file isn't a valid XZ-compressed file :
$ xzcat logfile.xz
xzcat : logfile.xz: Format de fichier inconnu
(which, in French, means "unknown file format").
When I use just cat
, the file is displayed correctly, with some weird data at the end (the command launched in the script is rsync
) :
& cat logfile.xz
sending incremental file list
prog/testfile
sent 531.80K bytes received 2.71K bytes 1.07M bytes/sec
total size is 14.21G speedup is 26,588.26
�7zXZ�ִF�D!��}YZ
logfile.xz seems to be a semi-valid XZ archive file, filled with uncompressed data. What am I doing wrong ?
PS : It works when I do something like that :
output = subprocess.check_output(command)
log_file.write(output)
...but given that the command takes a long time (it's a backup script), I want to be able to see the log (with xzcat
) before the end, to know what rsync is doing.