CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Advanced:
calling c programme in perl



Nov 29, 2003, 10:44 AM

Post #1 of 3 (1207 views)
calling c programme in perl Can't Post


I would like to use a C programme which will do the work. Is there a way to call a c programme inside Perl.



Nov 29, 2003, 4:47 PM

Post #2 of 3 (1204 views)
Re: [madhu_p] calling c programme in perl [In reply to] Can't Post

This perhaps is more of a basic/intermediate question but anyway...

If your C program generates output use:

my $out = qx/yourprog -any -switches/;

If not use....

system("yourprog") and die $!, $?;

(This post was edited by Recall on Nov 29, 2003, 4:47 PM)

Thaumaturge / Moderator

Dec 1, 2003, 3:40 AM

Post #3 of 3 (1197 views)
Re: [madhu_p] calling c programme in perl [In reply to] Can't Post

You would call a C program in exactly the same way as you would call any other external program. There are a number of options depending on exactly what you want to do.

* If you want to capture the data that the program writes to STDOUT then you can use backticks (` ... ` or qx( ... )) or open a pipe to read from the program (open PROG, '/path/to/prog |')

* If you don't need to capture that data then you probably want "system".

* If you want to _replace_ your process with the external program then you can use "exec".

* If you want to spawn a separate process that runs at the same time then you can use "fork" and "exec".

Dave Cross, Perl Hacker, Trainer and Writer
Get more help at Perl Monks


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives