I am using the exevcp
system call in order to execute "ping www.google.com"
. However, when I execute the code below:
#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
using namespace std;
int main(int argc, char *argv[]){
vector<char*> pingArgs;
pingArgs.push_back("www.google.com");
pingArgs.push_back(NULL);
execvp("ping", &pingArgs[0]);
return 0;
}
The below output is displayed, implying that I did not provide a link as an argument to the ping command. This seems strange, considering that in the vector which stores the arguments, I clearly added "www.google.com"
:
Usage: ping [-aAbBdDfhLnOqrRUvV64] [-c count] [-i interval] [-I interface]
[-m mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos]
[-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option]
[-w deadline] [-W timeout] [hop1 ...] destination
Usage: ping -6 [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface]
[-l preload] [-m mark] [-M pmtudisc_option]
[-N nodeinfo_option] [-p pattern] [-Q tclass] [-s packetsize]
[-S sndbuf] [-t ttl] [-T timestamp_option] [-w deadline]
[-W timeout] destination