Need help for basic use of perlembed

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I've integrated a perl interpreter into my C++ app with perlembed.

Now, I'd like to call a script with arguments and get return value
back, but I don't manage.
The fonctions perl_parse() and perl_call_argv() doesn't seem to do that
- with perl_parse(), I can call my perl script but no arguments are
- with perl_call_argv(), I can call perl and pass arguments but only to
a subroutine of the script, not to the whole script.

Does anyone know the way to do this basic use?
I'm also looking for detailled documentation about perlembed

Thank you in advance


Re: Need help for basic use of perlembed

Quoted text here. Click to load it

There must be something wrong with how you're calling it then - that's
exactly what args 3 & 4 to perl_parse() should be - argc (the count of
arguments) and argv (a C array of C strings).

Quoted text here. Click to load it

Have a look at "perldoc perlapi".


Re: Need help for basic use of perlembed

Ok, so here is my code:

my_perl = perl_alloc();
perl_construct( my_perl );
char *embedding[] = ;
int perlres = perl_parse(my_perl, xs_init, 6, embedding, NULL);

and I'd like to do as this command line :
"perl < infile > outfile"

Thanks for this quick answer Sherm.


Re: Need help for basic use of perlembed

Please quote some context when replying, thank you.

Mélanie FERELLOC wrote:
Quoted text here. Click to load it


I'm sorry I don't know the actual answer to your question (as I've
never done embedded Perl stuff), but I can tell you why this is
failing.  You are trying to pass the '<', 'infile', '>', 'outfile' as
command line arguments to the perl process.  Those should not be
command line arguments at all.  Those are shell meta-characters that
tell the invoking shell to redirect input and output.  The perl process
itself never sees those.  For example:

use strict;
use warnings;

print "Arguments: @ARGV\n";

Try calling this script as:
perl foo bar > output.txt

The results will be the file output.txt created with the line:
Arguments: foo bar

'>' and 'output.txt' are arguments to the invoking shell, not to the
perl process itself.

To solve your problem, you'll have to determine how perlembed allows
you to redirect input and output before invoking the perl process.  I
don't know how this is done, but perhaps it will aid your searching if
you look for keywords such as "redirect" rather than "arguments" or
"command line".

Paul Lalli

Re: Need help for basic use of perlembed

Quoted text here. Click to load it

Like Paul said, the "< infile" and "> outfile" aren't passed as arguments to, they're interpreted by the shell.

To achieve something similar with an embedded Perl, you could try using
freopen() to redirect stdin and stdout to the appropriate files, before
constructing a Perl interpreter and running your Perl code.


Site Timeline