0

I have the following python code, but no matter what combination of options I use it will not log to the file - It keeps logging to the terminal... The log file is empty with nothing in. Where am I going wrong?

I've tried a number of subprocess functions passing different parameters all without much luck.

import subprocess

logfile = open("runlog.txt", "w");

subprocess.call("rm -rf /opt/playlistscraper/downloaded/*.json", stdout=logfile, shell=True);
subprocess.call("scrapy crawl radio1 -o/opt/playlistscraper/downloaded/radio1.json", stdout=logfile, shell=True);
Scott Robinson
  • 583
  • 1
  • 7
  • 23
  • Is it logging to stderr? – James Mills Jun 13 '15 at 09:44
  • 1
    Yes - It is. Thank you for suggesting this. I did not know much about stdout and stderr so a quick google on the both of them after your suggestion makes sense! :) – Scott Robinson Jun 13 '15 at 09:47
  • You don't need subprocess for this at all, if you do use it you should pass a list of args without shell=True and also use `check_call` – Padraic Cunningham Jun 13 '15 at 10:17
  • In general, depending on the child process, just redirecting `stdout`, `stderr` to a file might not be enough; you might need a [pseudo-tty or call `screen` utility to capture the output](http://stackoverflow.com/a/25968448/4279) – jfs Jun 13 '15 at 14:01

0 Answers0