-
-
Save vigliag/4713452 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <sys/wait.h> | |
#include <errno.h> | |
#include <limits.h> | |
#include <string.h> | |
extern int errno; | |
int main(){ | |
pid_t id; | |
int status; | |
char executeyn; | |
char *curpath; | |
printf("Avviato Compila ed esegui\n"); | |
id=fork(); | |
if(id==-1){ | |
perror("errore nella fork"); | |
} else if(id==0){ | |
//puts("Avvio gcc"); | |
execlp("gcc", "gcc", "main.c", "-o", "main", "-pthread", 0); | |
} else { | |
waitpid(id,&status,0); | |
status = WEXITSTATUS(status); | |
if(!status){ | |
curpath=getcwd(NULL, PATH_MAX); | |
strcat(curpath, "/main"); | |
printf("compilazione terminata correttamente. Eseguire? %s \n", curpath); | |
executeyn = getchar(); | |
if (executeyn=='y'){ | |
execl(curpath, "main", 0); | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment