calling Perl from C

Hi,

I am trying to execute a perl script from c program.
I tried using system command.

system("perl test.pl filename") ;

This perl program takes filename as input and prints a number
to screen.

I need to get that returned number in C program.
system command is executing perl program, but I am not
able to get the return number. How I can get the return
value in c.

Thanks,
kk.

Hi!

Two simple ways of getting the output are:

1.) system("perl test.pl filename > output.txt"); ----> and then open the file output.txt and read it for the output.

2.) popen("perl test.pl filename", "r"); and read the output, which is the method I suggest. ----> See the man pages of popen()

Rgds
SHAIK

u dont even need to use
system("perl test.pl filename") ;

better put the first line of your PERL file as #!/usr/bin/perl

then u can directly use

system("test.pl filename >output")
and then read from this output file

:slight_smile:

How to pass the return value to C program?