Phoncible
01-24-2010, 05:04 AM
trying to read in a command from a user and then execute using execvp (for a linux machine)
char* cmd[4];
printf("what command\n");
scanf("%s",&cmd[0]);
cmd[1] = NULL;
execvp(cmd[0],cmd);
This doesn't work. Trying w/ the simple command of "ls" which should just show the contents of the current directory in linux, but it just prints a blank line.
Have also tried scanf("%s",cmd) and other variations along those lines.
Tried w/ getline and it just printed out junk.
Any help with this would be useful. Thanks
char* cmd[4];
printf("what command\n");
scanf("%s",&cmd[0]);
cmd[1] = NULL;
execvp(cmd[0],cmd);
This doesn't work. Trying w/ the simple command of "ls" which should just show the contents of the current directory in linux, but it just prints a blank line.
Have also tried scanf("%s",cmd) and other variations along those lines.
Tried w/ getline and it just printed out junk.
Any help with this would be useful. Thanks