• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

calling C programs from perl scripts

MrDudeMan

Lifer
here is my algorithm:

call perl script - pass it 2 files to do some work on (i.e. perl_prog file1 file2)
call C program and pass it file1 to do some work on
C file creates an output file, file3, based on file1
compare file2 and file3
...if different return 1 else return 0

i am new at perl and i cant figure out how to pass in files from the command line and then pass them to a C program.

can anyone give me a boost?
 
Originally posted by: jman19
Use a shell script?

im pretty new to unix/perl, so i dont really know how to do a shell script either. i know this is pretty basic, and im trying to teach myself with a book, but i cant seem to figure out how to do this.

fyi, i know c++ very well and c so-so. those arent my problems.
 
#!/usr/local/bin/perl
use strict;
my $file1 = shift;
my $file2 = shift;
my $file3 = "name_of_file_from_c_script";

my $cmd = "c_program $file1";
if(system($cmd)!=0)
{
die "c_program failed\n";
}

.... from here on out you can do whatever you want with the files since once system call is returned you will have file3 generated
 
Originally posted by: alexeikgb
#!/usr/local/bin/perl
use strict;
my $file1 = shift;
my $file2 = shift;
my $file3 = "name_of_file_from_c_script";

my $cmd = "c_program $file1";
if(system($cmd)!=0)
{
die "c_program failed\n";
}

.... from here on out you can do whatever you want with the files since once system call is returned you will have file3 generated

i dont understand where $file3 was used in your script. can you please explain?
 
Originally posted by: MrDudeMan
Originally posted by: alexeikgb
#!/usr/local/bin/perl
use strict;
my $file1 = shift;
my $file2 = shift;
my $file3 = "name_of_file_from_c_script";

my $cmd = "c_program $file1";
if(system($cmd)!=0)
{
die "c_program failed\n";
}

.... from here on out you can do whatever you want with the files since once system call is returned you will have file3 generated

i dont understand where $file3 was used in your script. can you please explain?

You said: C file creates an output file, file3, based on file1
So if you know the name you can store it in the $file3 variable for use later

The $file2 and $file3 are meant to be used after to compare file2 and file3, I did not code that part, just did the part of running the script and having the filenames available in the 3 $file# variables.
 
Originally posted by: alexeikgb
Originally posted by: MrDudeMan
Originally posted by: alexeikgb
#!/usr/local/bin/perl
use strict;
my $file1 = shift;
my $file2 = shift;
my $file3 = "name_of_file_from_c_script";

my $cmd = "c_program $file1";
if(system($cmd)!=0)
{
die "c_program failed\n";
}

.... from here on out you can do whatever you want with the files since once system call is returned you will have file3 generated

i dont understand where $file3 was used in your script. can you please explain?

You said: C file creates an output file, file3, based on file1
So if you know the name you can store it in the $file3 variable for use later

The $file2 and $file3 are meant to be used after to compare file2 and file3, I did not code that part, just did the part of running the script and having the filenames available in the 3 $file# variables.

ahh ok. thanks. that helps a lot.
 
Back
Top