Perl call C programs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl call C programs
# 1  
Old 06-17-2008
Perl call C programs

Hi,

I am a beginner in Perl programming. Now i need to call a C program from a perl program ...Can any one please help me and give any details how i can do this.

Thanks and Regards
# 2  
Old 06-17-2008
The system() command can invoke any external program. If the C program is not compiled, you need to compile it before you can invoke it (from Perl or otherwise), of course. Or, for an advanced and somewhat complex approach, have a look at the Inline::C module for Perl.
# 3  
Old 06-17-2008
Re: System

Hi,

Thanks for the quick reference...Will system functions be able return values or just the return code.I need to pass parameters to the C program and return some values.Can you provide a sample?

Thanks and Regards
Jithin.G
# 4  
Old 06-17-2008
Code:
if (($retcode = system("ls -l /etc /no/such/file")) == 0) { print "Success (exit code 0)\n"; }
else { print "Error: return code ", $retcode >> 8, "\n"; }

I recommend reading the documentation.

If you want to capture the actual output from an external command, use backticks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Difference between inbuilt suid programs and user defined root suid programs under bash shell?

Hey guys, Suppose i run passwd via bash shell. It is a suid program, which temporarily runs as root(owner) and modifies the user entries. However, when i write a C file and give 4755 permission and root ownership to the 'a.out' file , it doesn't run as root in bash shell. I verified this by... (2 Replies)
Discussion started by: syncmaster
2 Replies

2. Shell Programming and Scripting

How to call different programs based on requirement?

Hi Team, I have four shell scripts and i need to put it into one script and call based on requirement. For example: If server is Linux and version of my software version is 5 then it should call 1st scipt If server is Solaris and version of my software version is 6 then it should call... (16 Replies)
Discussion started by: darling
16 Replies

3. Shell Programming and Scripting

Call .profile in perl script

Hello Gurus Can anyone please let me know how to call .profle file in perl script When I am calling the .profile file its giving error Shall I create unix script which has .profile command and call perl script internally (2 Replies)
Discussion started by: Pratik4891
2 Replies

4. Shell Programming and Scripting

How to call a background process in perl?

Hi, I want to put the following code as a parallel or background process The program is as below: $n=10; #Count of files to be created. for($j=0;$j<=$n;$j++) { open(FH,">files_$j.txt") || warn "cannot create a file\n"; { print FH "count of file: $j\n"; #Sample data to be written. just... (5 Replies)
Discussion started by: vanitham
5 Replies

5. Shell Programming and Scripting

Running programs in perl

I am trying to run a program called GMT using perl. Cannot make to run. I have tried using exec("date"); as a test but when I use exec($try); nothing happens. #!/usr/bin/perl print "$#ARGV\n"; if ($#ARGV != 3) { print "usage: jcdplot.perl\n"; exit; } $h = $ARGV;... (1 Reply)
Discussion started by: kristinu
1 Replies

6. UNIX for Dummies Questions & Answers

Are programs like sys_open( ) ,sys_read( ) et al examples of system level programs ?

Are the programs written on schedulers ,thread library , process management, memory management, et al called systems programs ? How are they different from the programs that implement functions like open() , printf() , scanf() , read() .. they have a prefix sys_open, sys_close, sys_read etc , right... (1 Reply)
Discussion started by: vishwamitra
1 Replies

7. Infrastructure Monitoring

diffrence between method call and function call in perl

Hello, I have a problem with package and name space. require "/Mehran/DSGateEngineLib/general.pl"; use strict; sub System_Status_Main_Service_Status_Intrusion_Prevention { my %idpstatus; my @result; &General_ReadHash("/var/dsg/idp/settings",\%idpstatus); #print... (4 Replies)
Discussion started by: Zaxon
4 Replies

8. Shell Programming and Scripting

working with other programs in perl

Hi, I'm still new to perl, and I'm trying to figure out how to work with data output from another program. For example, from a command line I can run "foo -xyz" and it will produce the output I am looking for, which is several lines of text that I will then parse and manipulate within the perl... (6 Replies)
Discussion started by: Decoy
6 Replies

9. UNIX for Dummies Questions & Answers

how to call two programs simultaneously

Hi, i want to call two programs simultaneously from a currently running program so as to distribute the job and fasten the speed. As of now I call the programs one after the other within the main program. e.g. `perl A.pl`; `perl B.pl`; how can I run the two paralelly? urgent ... please... (1 Reply)
Discussion started by: vipinccmb
1 Replies

10. Programming

call functions from diferents programs

hi i have ten program in C, and there are functions what are in all the programs. so, i want to make a directory to store all the functions what are in all the programs, and call them from the C programs. (sending variables and values) is that possible?¿? how ca i do that?¿? any idea,... (1 Reply)
Discussion started by: DebianJ
1 Replies
Login or Register to Ask a Question