You could use stdout
parameter to redirect output from a subprocess to a file:
import shlex
from subprocess import check_call
with open('outputfilename', 'wb', 0) as outputfile:
check_call(shlex.split(cmd), stdout=outputfile)
Do you know what I should add to the command to prevent the subprocess from printing warning/errors to the shell ?
Just set stderr=subprocess.STDOUT
to merge stdout/stderr. Or redirect stderr
to os.devnull
to discard the output.