在 c++ 中下载文件时执行无限循环?
我想下载一个 html 文件,通过使用这个 bash 命令
system("wget -q -E -O sample.html http://www.XXX.com");
有时文件可能会很大,所以我想做一个无限循环,直到文件下载完毕。是否可以?如果是,该怎么做?
主要目标:
其余代码
下载 html 文件,然后继续执行我自己解决的 。谁能关闭这个问题。我非常抱歉
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
system()
将阻塞,直到命令执行完毕。您无需执行任何特殊操作即可等待它。system()
will block until the command has finished executing. You don't have to do anything special to wait for it.您应该使用
popen
和合适的wget
模式来输出机器可读的信息。You should use
popen
and a suitable mode ofwget
that outputs machine readable information.你应该在循环中使用某种计时器/延迟(比如每秒检查一次),以免 CPU 烧坏:)
You should use some kind of timer / delay for the loop (say check every second) to not fry that CPU :)
您不会希望对不需要“软件定时”的事情执行“无限循环”。相反,我会做一个循环,让代码休眠直到下载完成(定期休眠并检查是否完成,如果没有,再休眠一些,如果是,则继续)。使用无限循环会不必要地占用您的 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:
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