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
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 );
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With