On Thu, Mar 07, 2013 at 10:21:40AM +0100, WFB wrote:
> Hi, List,

Hello,

> To test our software I use perl to start it several times. My
> perl script gather some information and start then the program
> with different parameters.
> 
> It works very well, but I have a problem with the return values
> of our program. This return codes are all in an area from 55000
> to 60000. I use open to invoke our program and print the
> output. Finally I use the $? variable and print the error code
> in case of an error.
> 
> sub start_test_runner {
> my ($tr = shift, $tr_params) = @_;

I don't see a need for shift here. You can just assign the
arguments array to your list of parameters.

  my ($tr, $tr_params) = @_;

>  my $pid = open(my $trexe, "$tr \"$tr_params\" |") or die "Could not start
> TestRunner. $!\n";

Instead of escaping the double-quotes consider using the qq//
operator instead. You should also prefer the 3-argument open.

  my $pid = open(my $trexe, '-|', qq($tr "$tr_params") or
      die "Could not start TestRunner. $!";

>  while(<$trexe>) {
>  print $_ if $verbose;

No need to reference the default variable with print. That is
implied with no arguments.

  print if $verbose;

> }
> waitpid($pid, 0);
> close($trexe);
> my $tr_ret = ($?>>8);
> 
> return $tr_ret;
> }
> 
> now I read the perldoc perlvar section about $? and realised that only the
> above 8 bits are used for the return value. The first 8 bit are used for
> the system codes. As far as I that understand fit just 256 values in those
> 8 bits.
> Obviously, the error codes given back from my scripts are always wrong.
> For example, if the error code is 55028 I get 62464. With right shift the
> script prints 244.

I think on most platforms 0-255 is the range of possible exit
codes. What platform are you on?

Apparently Windows supports 32-bit integers... The Web suggests
that if you want to get full 32-bit integers on Windows then you
should use the Win32::Process module instead of open. It's not
portable, but at least it will do what you need.

Note: 55028 & 255 = 244. So what is happening is the original
exit code is being truncated down to one byte.

Regards,


-- 
Brandon McCaig <bamcc...@gmail.com> <bamcc...@castopulence.org>
Castopulence Software <https://www.castopulence.org/>
Blog <http://www.bamccaig.com/>
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'

Attachment: signature.asc
Description: Digital signature

Reply via email to