http://www.perlmonks.org?node_id=1229173


in reply to Pass signals and argv from C to embedded Perl

I can not figure out how to pass C's argv to Perl script as ARGV

You don't want to pass argv to the Perl interpreter; you want to pass arguments to it. That's done via 3rd and 4th argument of perl_parse.

char** perlargv = malloc( (argc+3) * sizeof(char*) ); perlargv[0] = "perl"; perlargv[1] = "-e"; perlargv[2] = "1"; perlargv[3] = "--"; int i = argc-1; while (i--) perlargv[i+4] = argv[i+1]; perl_parse(my_perl, NULL, argc+3, perlargv, NULL);

Don't forget to free the memory you allocated for the arguments. This should be done after freeing the Perl interpreter.


I can not figure out how to pass any signal the C program gets, for example Ctrl-C/SIGINT, to the Perl script.

You don't want to "pass signals"; you simply want the Perl program to handle them. That's done by setting $SIG{INT}. The system calls whatever handler was set to handle the signal, whether this was done by C code or by Perl code. You've already proved that this works.

As for not getting the message, could you have been suffering from buffering because you didn't end your messages with a line feed?