I have subprocess.call(["ddrescue", in_file_path, out_file_path], stdout=drclog)
. I'd like this to display the ddrescue in the terminal as it's running and write the output to the file drclog. I've tried using subprocess.call(["ddrescue", in_file_path, out_file_path], stdout=drclog, shell=True)
, but that gives me an input error into ddrescue.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
If
ddrescue
doesn't change its output if its stdout/stderr are redirected to a pipe then you could usetee
utility, to display output on the terminal and to save it to a file:If it does then you could try to provide a pseudo-tty using
script
utility:If it writes directly to a terminal then you could use
screen
to capture the output:The output is saved in
screenlog.0
file by default.To emulate the
tee
-based command in Python without callingtee
utility:To call the
tee
-based command in Python usingshell=True
:To emulate the
script
-based command:To call
screen
command in Python:The solution that worked for me was
subprocess.call(["ddrescue $0 $1 | tee -a drclog", in_file_path, out_file_path], shell=True)
.