novice Perl programmer here!.
I’m using the system() function to get the return code for an external program (in this case – php), however, the command’s output is still printed to the screen.
How do I prevent it from doing so?
My code is:
use strict; use warnings;
print 'Return code:', system('php -l wrong.php'), "\n";
This code does print the return code, but it also print the the output of the command executed.
Any help will be appreciated!
EDIT: further testing shown that this happens while only using the php lint command.. using it with other commands doesnt print anything…
If you are on a UNIX-like OS, you should be able to redirect the output in the command:
Try:
system('php -l wrong.php >> /dev/null')to get rid of what’s being sent to stdout.You could also open the command with a pipe to handle the output directly, which should be more portable.