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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.