In Python , If I am using “wget” to download a file using os.system(“wget ), it shows on the screen like:
Resolving...
Connecting to ...
HTTP request sent, awaiting response...
100%[====================================================================================================================================================================>] 19,535,176 8.10M/s in 2.3s
etc on the screen.
What can I do to save this output in some file rather than showing it on the screen ?
Currently I am running the command as follows:
theurl = "< file location >"
downloadCmd = "wget "+theurl
os.system(downloadCmd)
To answer your direct question, and as others have mentioned, you should strongly consider using the subprocess module. Here’s an example:
But, no need to call out to the system to download a file, let python do the heavy lifting for you.
Using urllib,
Or urllib2,
local_filenameis the destination path of your choosing. It is sometimes possible to determine this value automatically, but the approach depends on your circumstance.