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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.