Search code examples
pythonwgetopenwrt

Get wget output in python variable


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')

Solution

  • In general you can catch stdout of programs with subprocess

    import subprocess
    
    output = subprocess.check_output('ping localhost', stderr=subprocess.STDOUT, shell=True)