I've forked a child process which then calls a bash script using execv
, the way i'm passing command line arguments to the script, It does not print first argument on doing echo $1
inside the script.
std::string s = std::to_string(c_no);
char *args[] = {(char *)s.c_str(), NULL};
pid_t pid = fork();
if(pid == 0){
execv("./ckpnt.sh", &args[0]);
}
consider c_no
to be any integer.
What is the correct way to do this?
I've already refrenced this link How to pass command line arguments from C program to the bash script? but this answer uses system
system call and i try to not use that.