Why to shift bits "$? >> 8" when using Perl system function to execute command

Viewed 8193

I have seen this in many places in Perl scripts:

system("binary");
$exit_code = ($? >> 8)
exit($exit_code)
  1. Why should I use this? Is there an alternative way?

  2. I am calling some binary in system(binary) which I created in C++, which does some stuff and if it fails it gives assert. When I reboot a Linux machine, the stuff which is going fails, and my binary generates assert as expected. But on the Perl side where I called it, it throws a 134 error code, which after 134 >> 8, becomes 0. Ultimately it is making my failure operation a success (which I don't want).

2 Answers
Related