简体   繁体   中英

c wrapper to a perl script that accepts arguments hard coded in the wrapper

My question might be described as the reverse of "Passing cmd line arguments through a C setuid wrapper...". That question asks how to run this ./cwrapper perl.pl --option1 --option2

In my case, the Perl script is embedded in the wrapper. This wrapper comes from page 570 "Programming Perl". And it works---until I add an argument following the script in the wrapper.

THIS WORKS -- perl_script.pl outputs expected results:

#define REAL_SCRIPT "/path/to/script/perl_script.pl"
main (ac, av)
    char **av;
{
    execv(REAL_SCRIPT, av);
}

THIS DOES NOT WORK--eg perl_script outputs nothing to stdin or stderr. Note the "arg=12345":

#define REAL_SCRIPT "/path/to/script/perl_script.pl arg=12345"
main (ac, av)
    char **av;
{
    execv(REAL_SCRIPT, av);
}

Thanks for any clues. John

The first argument of execv() is the path to the executable to execute. It works when you pass the args as the second parameter to execv() , but when you pass the extra param in as part of the executable's name, execv() fails.

I notice a lack of error handling in your example. I infer from the lack of an error message reported above that you're not checking for and handling errors from execv(). It is probably telling you why it won't run your program. It returns and integer, and if non-zero, you should look up the error using perror() .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM