I am coding on Windows, so fork() is not available. Now, i need to run execl(), but it is an end point of my program! I thought of creating a separate thread to run execl(), which is created successfully, and runs well also. But still my program comes to an end after thread is over.
Function running thread–It is inside class wScoreget:-
int refresh_score_now(){
pthread_t t;
if(pthread_create(&t,NULL,s.basicgetscore,&s)==-1){
printf("Error: wScoreget:3");
exit(4);
}
void *a;
if(pthread_join(t,&a)==-1){
printf("Error: wScoreget: 4");
exit(4);
printf("Running thread.\n");
getch();
}
}
Calling from main:-
int main(){
wScoreget new_ws;
new_ws.refresh_score_now();
printf("reached to the end\n");
getch();
}
I am expecting console to print- “reached to the end”
But on execl() it exits.
NOTE: execl() is running curl. Its output is going to a text file. Now, if stdout is changed, curl shows download timing and other data on the console. THAT data comes to console anyways.
Is there a way I can do this without using CreateProcess? And if I use CreateProcess, which libraries do I have to install on Windows(I am using MingW + Codeblocks).
Try using
spawnorposix_spawn. It should replace fork + exec.