Skip to content

Instantly share code, notes, and snippets.

@vigliag
Created February 5, 2013 10:02
Show Gist options
  • Save vigliag/4713452 to your computer and use it in GitHub Desktop.
Save vigliag/4713452 to your computer and use it in GitHub Desktop.
#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