Reputation: 38270
To compile a C++
project, I want to write a perl
script to compile my program and see if the compilation went wrong or not. If the compiler gives any compilation error, I'll need to perform some other task.
The perl
script will be something like this:
@l1 = `find . -name '*.c'`;
@l2 = `find . -name '*.cpp'`;
@l3 = `find . -name '*.cc'`;
my $err;
my $FLAGS = "-DNDEBUG"
push(@l , @l1, @l2, @l3);
chomp(@l);
foreach (@l) {
print "processing file $_ ...";
$err = `g++ $_ $FLAGS`;
if($err == something) {
#do the needful
}
}
so what should be something?
Upvotes: 1
Views: 146
Reputation: 182774
You should check $?
instead, after g++...
.
$?
The status returned by the last pipe close, backtick (`` ) command, successful call to wait() or waitpid(), or from the system() operator.
The exit value of the subprocess is really
($?>> 8)
So you should check if g++
returned 0
(success) or non-zero
.
if ($? >> 8) {
/* Error? */
}
Upvotes: 6