0
Updated code ,it does not execute commands
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
void ExeclLS(int argc, char **argv) {
char *args[] = {"ls", "-aF", "/", 0};
char *env[] = { 0 };
printf("Rodando o bin/ls\n");
execve("bin/ls", args, env);
}
void ExeclTop(int argc, char **argv) {
char *args[] = {"top", "-aF", "/", 0};
char *env[] = { 0 };
printf("Rodando o bin/top\n");
execve("/usr/bin/top", args, env);
}
int main() {
int valorMenu;
printf("Digite o comando : 1 - ls , 2-top\n");
scanf("%i",&valorMenu);
if (valorMenu == 1){
printf("Rodando o bin/ls\n");
ExeclLS(0, NULL);
}else{
printf("Rodando o bin/Top\n");
ExeclTop(0,NULL);
}
perror("execve");
exit(1);
return 0;
}
Someone can help me?
The
perror()
gives some interesting error message?– pmg
This code runs normally, but when I put "/bin/top" it prints "execve" and then no file found
– Andreia Oliveira
So ... this means that the "top" is not in the "/bin" directory. It does
whereis top
to try to find out where he is.– pmg
Thank you! You helped me so much
– Andreia Oliveira
Your structure of
if
/if
/else
is not well organized. Theelse
only concerns the secondif
.– pmg
I updated the code there
– Andreia Oliveira
foul
/
inexecve("bin/ls", args, env);
==>execve("/bin/ls", args, env);
– pmg