in reply to Running a C Program within Perl.
'system' just returns 0 on success and 1 on failure therefore you should test for it.my $cmdToRun = "/path-to/the-c-prog"; system ($cmdToRun) && die "system $cmdToRun - $!\n";
Using backticks is useful if you need to capture output from the program you are calling.my $cmdToRun = "/path-to/the-c-prog"; my @results = `$cmdToRun`;
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.my $cmdToRun = "/path-to/the-c-prog"; open (CMD, "$cmdToRun |") || die "open $cmdToRun - $!\n"; while (<CMD>) { # loop through the program output here... }
|
|---|