http://www.gnu.org/software/libc/manual/html_node/Executing-a-File.html
— Function: int execv (const char *filename, char *const argv[])
The execv function executes the file named by filename as a new process image.
The argv argument is an array of null-terminated strings that is used to provide a value for the argv argument to the main function of the program to be executed. The last element of this array must be a null pointer. By convention, the first element of this array is the file name of the program sans directory names. See Program Arguments, for full details on how programs can access these arguments.
Since sending the program name for the first element of the array is only a convention, and the OP created his array with a number in the first element and passed it to execv wouldn't that get used? It seems like you could send whatever you like as the first element.
Update:I did a test to see what would happen and the first element of the array passed to execv doesn't show up in the Perl script. Interesting.
#include <stdio.h> void main(void) { char *temp[] = {"1", "2", "3", NULL}; printf("Hello from c\n"); execv( "./script.pl", temp ); printf("error"); }
#!/usr/bin/perl use warnings; use strict; print ">>@ARGV<< from Perl\n"; __DATA__ pi@raspberrypi ~/Desktop/perlmonks $ ./hello Hello from c >>2 3<< from Perl
In reply to Re^2: ARGV empty when calling Perl from C program
by Lotus1
in thread ARGV empty when calling Perl from C program
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |