2

I am able to download the file using wget and I can see the progress in the console, But how can we store this output into a python variable ?.

a sample code give below, I am excepting something like this.

output = os.popen('wget https://www.tutorialspoint.com/python3/python3_tutorial.pdf')
Arun
  • 1,149
  • 11
  • 22
  • Possible duplicate of [Assign output of os.system to a variable and prevent it from being displayed on the screen](http://stackoverflow.com/questions/3503879/assign-output-of-os-system-to-a-variable-and-prevent-it-from-being-displayed-on) – Peter Wood May 18 '17 at 13:28
  • @ Peter Wood,wget result is different than other os command results – Arun May 18 '17 at 13:30

2 Answers2

3

In general you can catch stdout of programs with subprocess

import subprocess

output = subprocess.check_output('ping localhost', stderr=subprocess.STDOUT, shell=True)
Serve Laurijssen
  • 9,266
  • 5
  • 45
  • 98
1

I wouldn't recommend using wget, use urllib instead: https://docs.python.org/2/library/urllib.html.

If you must use wget just read the output file after wget writes it.

os.system('wget https://www.tutorialspoint.com/python3/python3_tutorial.pdf -O your_file_path')
print open('your_file_path').read()
Mark Beilfuss
  • 602
  • 4
  • 12