문제

I'm trying to execute ping command within my program. I'm working on newest Raspian on RaspBerry Pi B Model. It tells me that: /bin/sh-c: 0: Can't open ping -c 1 192.168.0.12 My code(it's not finished jet, i know that following code can have some issues):

int status;
pid_t pid;
pid = fork();
const char* commandChar = commandName.c_str();
if(pid == 0)
{
    execl(SHELL, SHELL "-c", commandChar, NULL);
    _exit(1);
}else if(pid < 0)
{
    return false;
}
commandChar = NULL;
    delete commandChar;
return true;

Ping (/bin/ping) have rwsr-xr-x permissions, so why I can't execute it and how to make it work?

enter image description here

도움이 되었습니까?

해결책

execl expects a file path, you are giving it the file path "/bin/ping -c 192.168.0.12", which of course doesn't exist. Look at the man page for execl, you will see that the last argument is used for the arguments to the program to be run.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top