29 lines
620 B
C
29 lines
620 B
C
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
int main(int argc, char const *argv[])
|
|
{
|
|
printf("%d\n", argc);
|
|
if(argc < 2) {
|
|
printf("missing arguments\n");
|
|
return 1;
|
|
}
|
|
|
|
char * args[argc - 1];
|
|
for(int i=1; i < argc; i++) {
|
|
args[i-1] = (char *)malloc(sizeof(char) * strlen(argv[1]));
|
|
strcpy(args[i-1], argv[i]);
|
|
}
|
|
//args have to be null terminated
|
|
args[argc - 2] = NULL;
|
|
|
|
printf("starting %s\n", argv[1]);
|
|
|
|
if(execv(argv[1], args)) {
|
|
printf("\nfile not found, or error happened\n");
|
|
return 1;
|
|
}
|
|
}
|