Basically, there are three ways to run an external prog -
1 -
system.
2 -
backticks.
3 -
open a pipe.
system:
my $cmdToRun = "/path-to/the-c-prog";
system ($cmdToRun) && die "system $cmdToRun - $!\n";
'system' just returns 0 on success and 1 on failure therefore you should test for it.
backticks:
my $cmdToRun = "/path-to/the-c-prog";
my @results = `$cmdToRun`;
Using backticks is useful if you need to capture output from the program you are calling.
pipe:
my $cmdToRun = "/path-to/the-c-prog";
open (CMD, "$cmdToRun |") || die "open $cmdToRun - $!\n";
while (<CMD>) {
# loop through the program output here...
}
UPDATE Of course this assumes you meant calling an external c prog from within perl. After reading
sniper's post I realize you could have meant running actual c code from within perl - in that case Inline.pm would be the natural choice.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.