Calling a c program using perl script

On bash I run precompiled c Program as follows:

./create_cust 1 10000 US S > us_cust.csv

create_cust is a c program and requires 4 parameters.
I am redirecting the output of this program to csv file

I need to run this same program in perl

I am aware of exec command though not sure it will work.

Can anybody will direct me to a code which is calling a parameterised c program through perl and how to redirect its output to csv file???

Why not simply try and see what happens :confused:
I'd first try it on the command line, if it works then put it in the script.

perl -e 'exec("create_cust 1 10000 US S > us_cust.csv");'

or

perl -e 'system("create_cust 1 10000 US S > us_cust.csv");'

Inside the perl script, something like following should also work:

my $par1=1;
my $par2=10000;
my $par3='US';
my $par4='S';
system("create_cust $par1 $par2 $par3 $par4 > us_cust.csv");

It gives error that create_cust is not internal / external command or oparable program or batch file

And

perl -e 'exec("./create_cust 1 10000 US S > us_cust.csv");'

?

. not recognised as external or internal command

Strange... I wonder if a simple

perl -e 'exec("ls -l")'

will work? If this won't work too, than there might be something wrong with your Perl.
However I have tried to run a c program before I posted here and it worked for me :frowning:

I assume you were in directory where your c program is stored when you issued the Perl command? Else one needs to specify the full path to that program.

I am using cygwin and have installed activestate for perl on windows.

I am going in bash of cygwin and going to directory where program executable is present and executing above command.

It gives error.

The other code which u gave for ls -l runs properly on cygwin

All right, this is the last idea I have, namely to check if your program has to be in PATH in order to work:
run "which ls" to see in which directory the ls command is present, the output will most likely be /bin/ls
Now copy the create_cust file in /bin and try to run (from any directory):

perl -e 'exec("create_cust 1 10000 US S > us_cust.csv");'

If this works, delete the two files (create_cust and us_cust.csv) from /bin and add the actual directory, where the create_custom file is located to the PATH variable.
Hope I was clear?
Let me know how it goes.