Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling a make utility/file through a perl script

Tags:

makefile

perl

Is there any way i can call a make utility through perl script. I used the below code in myscript

$cmd=system("/...path../make");
print "$cmd";

but its not working

like image 845
Manish Kumar Avatar asked Feb 20 '26 17:02

Manish Kumar


2 Answers

You can call any command you wish. It is typically done in backquotes for simplicity:

my $output = `make`;
print( $output );

Another common technique is to open a process for reading just like a file:

my $filehandle;
if ( ! open( $filehandle, "make |" ) ) {
    die( "Failed to start process: $!" );
}
while ( defined( my $line = <$filehandle> ) ) {
    print( $line );
}
close( $line );

The advantage of this is you can see the output as it is delivered from the process.

You may wish to capture STDERR output as well as STDOUT output by adding 2>&1 to the command line:

my $filehandle;
if ( ! open( $filehandle, "make 2>&1 |" ) ) {
    die( "Failed to start process: $!" );
}
while ( defined( my $line = <$filehandle> ) ) {
    print( $line );
}
close( $line );
like image 157
PP. Avatar answered Feb 22 '26 16:02

PP.


You just need to use backquotes.

my $command = `make`;
print $command;

The return value of system is the exit status. See here

EDIT: Link to system