I would like to know how to store the result of execvp to a char array as a string.
Below is my code:
Code:
int main () {
char response[1000];
char *buffer[100];
int pid, status;
printf("Please enter the shell command: ");
scanf("%s",&response);
pid = fork();
if (pid < 0) {
printf("Unable to create child process, exiting.\n");
exit(0);
}
if (pid == 0) {
printf("I'm the child.\n");
*buffer = response;
execvp(*buffer,buffer);
printf("execvp failed\n");
}
else{
wait(&status);
exit(0);
}
}
If a user types "ls" execvp displays the result of "ls" to the screen. I would like to store this in a char array as a string. Can anyone help me?
THanks in advance.
James