Calling a C-function froma Perl script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calling a C-function froma Perl script
# 1  
Old 05-07-2008
CPU & Memory Calling a C-function froma Perl script

Hi All,

How can we call a c function from a perl script?
Is it the same way as we do for shell script ?

Thanks in advance
JS
# 2  
Old 05-07-2008
I tried tuning the method to call c function from shell script .. but in vain ..
can some one please help
Thanks
JS
# 3  
Old 05-07-2008
Can you give us an example of what you want to do? It is unusual to attempt to call a C function from a script of any kind.
# 4  
Old 05-07-2008
ya sure ..a very simple example

my sample.c file is given below:

# include <stdio.h>
void pline(void);
main(int argc,char *argv[])
{
int i,j;

printf("Wow Entered main\n");

i=strcmp(argv[0],"pline"); /*just to test*/
j=strcmp(argv[1],"pline"); /*just to test*/
printf("i=%d \n j=%d\n",i,j);

if(strcmp(argv[1],"pline") == 0)
{
pline();
printf("done\n");
}
}

void pline(void)
{
int i;
for(i=1;i<5;i++)
printf("Test \n");
printf("\n");
}

No call the function from a 1.pl file .. this is my requirement
i guess we need to get the executable of sample.c after compiling. this too is done and executable is generated.

Thanks
# 5  
Old 05-07-2008
This is the link where i have posted a solution for the shell script

https://www.unix.com/shell-programmin...ll-script.html
# 6  
Old 05-07-2008
I would describe that as 'running a compiled C programme' rather than 'calling a C function'. You can do that using the system command in perl.
# 7  
Old 05-07-2008
Thanks for pointing this out
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl script for Calling a function and writing all its contents to a file

I have a function which does awk proceessing sub mergeDescription { system (q@awk -F'~' ' NR == FNR { A = $1 B = $2 C = $0 next } { n = split ( C, V, "~" ) if... (3 Replies)
Discussion started by: crypto87
3 Replies

2. Shell Programming and Scripting

Calling function from another bash script

I would like to call functions from another bash script. How can I do it? Some code More code (11 Replies)
Discussion started by: kristinu
11 Replies

3. Shell Programming and Scripting

PERL: Function calling using parameters

I have two variables. I need to call them using the same function my $dat1 ="abc"; my $dat2 ="def"; my $check; filecheck($dat1,$dat2); sub filecheck($) { $check = shift; print "first name is $check\n"; } print "this is fine\n"; sub filecheck($) { $check = shift; print "second... (2 Replies)
Discussion started by: irudayaraj
2 Replies

4. Homework & Coursework Questions

Shell script calling Perl function, sort and find data, write to new files

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I must write a shell script that calls two external Perl functions--one of which sorts the data in a file, and... (6 Replies)
Discussion started by: kowit010
6 Replies

5. Shell Programming and Scripting

SHELL SCRIPT Function Calling Another Function Please Help...

This is my function which is creating three variables based on counter & writing these variable to database by calling another function writeRecord but only one record is getting wrote in DB.... Please advise ASAP...:confused: function InsertFtg { FTGSTR="" echo "Saurabh is GREAT $#" let... (2 Replies)
Discussion started by: omkar.sonawane
2 Replies

6. Shell Programming and Scripting

Question for calling oracle function from perl

Dear Sir/Madam, I use the following way to call the oracle stored procedure in a perl script, but I do not know how to call a oracle function by the following way ? # ARGV is the oracle stored procedure name with parameters $str = "sqlplus -s <<-eof \n" . "$db_login... (0 Replies)
Discussion started by: ili
0 Replies

7. Shell Programming and Scripting

Calling a C-function froma shell script

Hi, I have searched the forum for the query, But i didnt find an exact answer. I have a script(1.sh) and a c program(sample.c) sample.c contains many function definitions.( run(), find(), add() etc). I want to call functions in sample.c from 1.sh and use the return value in 1.sh... (3 Replies)
Discussion started by: jisha
3 Replies

8. UNIX for Dummies Questions & Answers

calling one function from another shell script

i have a function defined in one ksh (ksh 1) i want to use that function in another ksh (ksh 2) i am using . $<directoryname>/<ksh name> i am calling the function defined in ksh 1 in ksh 2 i want the returnstatus from the above operation but it is not executing the function what i... (1 Reply)
Discussion started by: trichyselva
1 Replies

9. Shell Programming and Scripting

$0 scope in function and calling script

Hi folks, I'm just running through an oreilly korn shell book but have witnessed an output difference on my own unix machine and the output provided in the book. Can anyone help? create a script called ascript as follows: function afunc { print in function $0: $1 $2 var1="in... (16 Replies)
Discussion started by: beckett
16 Replies

10. Programming

calling c++ function from script

hi, I just started to work on unix, I was wondering if it is possible to call a c++ function from a script. now, i don't mean starting a program, i mean dynamicaly calling a funtion (like working with a dll) thanks (3 Replies)
Discussion started by: Lebamb
3 Replies
Login or Register to Ask a Question