Issue
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.
Solution
First argument passed to a program is its name so currently your number ends up in $0
. args
should be:
char *args[] = {"./ckpnt.sh", (char *)s.c_str(), NULL};
Answered By - Botje Answer Checked By - Pedro (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.