This is taking all day to try to figure out why it's not working. This is with Python 3.6.
The goal is to capture the progress from a command line, shred as an example. Shred would output line by line of the progress.
With Python subprocess, it cannot seem to save any output to the file. I did this:
cmd_str="sudo shred -v /dev/sde"
f="/test.log"
with Popen(cmd_str, stdout=f, bufsize=1, universal_newlines=True) as p:
for line in p.stdout:
print(line, end='')
But it generated an error saying: FileNotFoundError: [Errno 2] No such file or directory: 'sudo shred -v /dev/sde': 'sudo shred -v /dev/sde' which makes no sense to me.
Simply put, I want a new line of output to be appended to the file and close it. So that way, the external program can check the log file to see how the progress is going.
I just observed that when I use tee to see if it's logging and it's not logging to the file either despite creating the log file.
UPDATE: I have tried every possible solution in this site and nothing worked. I am starting to think if it has to do with the fact that it's a progress bar that is not capable of being sent to stdout? These are tried and yet failed to work: