Q:

How to redirect apt-file update output

I want access the output from the command apt-file update in a python script.
Unfortunately, I am not able to access the output. My tries:
# Does not work:
popen_ret = subprocess.Popen([r'apt-file', 'update']), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = popen_ret.communicate()[0]
print output

# Without the "update" argument, it does work:
popen_ret = subprocess.Popen([r'apt-file'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = popen_ret.communicate()[0]
print output

My guess is that the problemis with apt-file itself as, even directly from the console, this creates an empty file:
apt-file update > delme.txt

Yet
apt-file > delme.txt

works fine.
Other peopele seem to have had the same problem (but no solution):
question posed at http://www.linuxquestions.org

A:

apt-file is a perl script calling another perl script diffindex-download.
All the output produce when apt-file update is run is generated by diffindex-download.
I'm not a perl expert but apparently this script write to /dev/tty and not to stdout. You can read about the difference here:
What is the difference between writing to STDOUT and a filehandle opened to "/dev/tty"? 
So if you want to redirect the output of this script you should do
script -c "apt-file update" output.log

