Calling a c program using perl script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Calling a c program using perl script
# 1  
Old 05-20-2010
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???
# 2  
Old 05-20-2010
Quote:
Originally Posted by gkbond
I am aware of exec command though not sure it will work.
Why not simply try and see what happens Smilie
I'd first try it on the command line, if it works then put it in the script.

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

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

Inside the perl script, something like following should also work:
Code:
my $par1=1;
my $par2=10000;
my $par3='US';
my $par4='S';
system("create_cust $par1 $par2 $par3 $par4 > us_cust.csv");

# 3  
Old 05-20-2010
It gives error that create_cust is not internal / external command or oparable program or batch file
# 4  
Old 05-20-2010
And
Code:
perl -e 'exec("./create_cust 1 10000 US S > us_cust.csv");'

?
# 5  
Old 05-20-2010
. not recognised as external or internal command
# 6  
Old 05-20-2010
Strange... I wonder if a simple
Code:
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 Smilie

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.

Last edited by pseudocoder; 05-20-2010 at 03:52 PM..
# 7  
Old 05-20-2010
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
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

calling a shell script present on another server using perl script.

Hi, I am working on a sever A. I want to write a perl script to execute a shell script persent on the server B. please help me in this. thanks in advance. (3 Replies)
Discussion started by: anandgodse
3 Replies

2. Shell Programming and Scripting

calling a perl script with arguments from a parent perl script

I am trying to run a perl script which needs input arguments from a parent perl script, but doesn't seem to work. Appreciate your help in this regard. From parent.pl $input1=123; $input2=abc; I tried calling it with system("/usr/bin/perl child.pl $input1 $input2"); and `perl... (1 Reply)
Discussion started by: grajp002
1 Replies

3. Shell Programming and Scripting

How to pass the environment name while calling java program from unix script?

Hi, I'm trying to test one unix shell script in dev environment. But I'm not sure how to pass the environment in my java program calling code. I'm trying to use -DconsumerEnv="DEV" but unfortunately I get 'null' while trying to print the value from java class. System.out.println("Environment: "+... (4 Replies)
Discussion started by: Pramit
4 Replies

4. Homework & Coursework Questions

Calling compiled C program with Perl program

Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text... (1 Reply)
Discussion started by: jdkirby
1 Replies

5. Shell Programming and Scripting

Calling perl script in shell program

How to call a perl script in shell program / shell scripting. PLS HELP ME (2 Replies)
Discussion started by: hravisankar
2 Replies

6. Programming

Calling a shell script from a C program

Hi, I have a shell script which connects to a database and fetches the count of the records from a table. I want to embed this whole script in a C program. Also the count fetched should be available in the C program for further usage. Please let me know how this can be done. Thanks (9 Replies)
Discussion started by: swasid
9 Replies

7. Shell Programming and Scripting

Calling a shell script from a C program

Hi, I have a shell script which connects to a database and fetches the count of the records from a table. I want to embed this whole script in a C program. Also the count fetched should be available in the C program for further usage. Please let me know how this can be done. Thanks ... (0 Replies)
Discussion started by: swasid
0 Replies

8. Shell Programming and Scripting

Calling 3 perl script from one

hi all, I have 3 perl scripts a.pl,b.pl and c.pl each of these work when i pass a date for eg: perl c.pl 2010-05-27 now i want to write a perl script that would call the 3 scripts and make it run all the 3 scripts (a.pl,b.pl,c.pl) parallelly rather than 1 after the other....... pls... (2 Replies)
Discussion started by: siva_nagarajan
2 Replies

9. Shell Programming and Scripting

Run shell script from C program by calling fork and execl

I need to write a c program that uses the fork and excel system calls to run the shell script mode invoked like this: "./mode 644 ls -l" (that is the argumetns will always be 644 ls -l) here's the mode script: #!/bin/sh octal="$1" shift find . -maxdepth 1 -perm $octal -exec $@ {} \; ... (3 Replies)
Discussion started by: computethis
3 Replies

10. Shell Programming and Scripting

Calling SHELL script from C program

Hi, I just tried to call a simple script from a pretty simple C program. I could not succeed :-( a message was thrown saying "sh: line 1: "Script name with path": Permission denied" The C program and shell script are below, both are in the same directory and shell script is given... (7 Replies)
Discussion started by: Chanakya.m
7 Replies
Login or Register to Ask a Question