using linux commands in my c++ program. Trying to download a url from a list of arrays, once one download finishes, the next to start…. currently only downloads the first location in the array, then stops.
Does somebody see the error i’m doing?
// Begin the downloading process
pid_t child = 0;
child = fork();
if ( child < 0)
{
cout << "Process Faileld to Fork<<endl;
return 1;
}
if (child == 0)
{
wait(NULL);
}
else
{
for(int i = 0; i < numberOfDownloads; i++)
{
execl("/usr/bin/wget", "wget",locations[i], NULL);
}
}
trying to download something with the command wget, but i get an error
execlreplaces the currently running process by the started process. So your loop body is only run once. You should put thefork()inside the loop, assuming you want to fork offnumberOfDownloadsinstances ofwget. (but be careful with such things)Otherwise, use
system(), which will not terminate your process but return to your loop afterwgetexits. Orpopen(), if you need more control over the process and want to readwgetoutput, without having to do all the I/O heavylifting yourself.