I want to download a html file, by using this bash command
system("wget -q -E -O sample.html http://www.XXX.com");
sometime the file might huge, so I was thinking to do an infinite loop until the 开发者_如何转开发file is downloaded. Is it possible? If yes, how to do it?
Main Objective:
Download the html file, then proceed with the rest of the codes
I solve it myself. Can anyone close this question. I am terribly sorry
system()
will block until the command has finished executing. You don't have to do anything special to wait for it.
You should use popen
and a suitable mode of wget
that outputs machine readable information.
You should use some kind of timer / delay for the loop (say check every second) to not fry that CPU :)
you will not want to do an 'infinite loop' for something that isn't necessary to be 'software timed'. Instead, i'd do a loop where you Sleep the code until the download is finished (sleep periodically and check to see if finished, if not, sleep some more, if so, continue on). Using an infinite loop will suck up your CPU unnecessarily and you usually want to avoid doing that.
My answer is:
while(system("wget -q -E -O sample.html http://www.XXX.com/")){
;
};
I know my answer is suck. Will try implement your guys answer later on. but I stuck again, I am posting another question here Read file and extract certain part only
精彩评论