On 7 March 2013 16:05, Brandon McCaig <bamcc...@gmail.com> wrote: > 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) = @_; > > Originally, it was: my $tr = shift; my $tr_params = shift; For the email I formatted into the new form and obviously missed to remove the shift :-)
> > 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. $!"; > I often read the three letter open hint here on the list, but I did not realize that that is also possible to use with pipes. Another thanks for the qq hint. > > > 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. > > I will use the Win32::Process module. I am on Windows 7 x64 and this will never run on any unix system. Thanks, for this tip and the link in the other email. Note: 55028 & 255 = 244. So what is happening is the original > exit code is being truncated down to one byte. > > Regards, > Thanks a lot, Brandon! > -- > 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' > > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.10 (GNU/Linux) > > iQIcBAEBAgAGBQJROKzUAAoJEN2n1gIi5ZPynHcQAKtqHtZdxzcBoZpkyVKaNTI4 > BF0AtlUesQwEh197pMgDHWLfGIFfG9yD1pTLPHgI9zUAnMIUd4VpMCy0PLOZo5XY > Lz+l51BSWS+v2O1tQyfhNhIMM+6uzXu1JoTsSyQbVUIjZBDn+MCUF067UUHfBEsh > XO00Vf4CT/9kIa71+PgNY7ql0mKM7VScAIanGnXVw+QEhiapPGHkl1/33mAD1HU0 > L5iTUJtunyvZLTn36gw4qoheJ0nGy1O0IbERp0wFyXaquizajBeYpx4RfnEDAEN3 > ykxDt7YcRD3TcHw1FayZb2x57QRX/CXLB8S50FgjM+0a5aD3PjvN/ECzdLN69raF > 7rqmQC+uZ8qnJo/Kq4w1BytQV+Kzc23jzg89gTM0oLHgJ+TsGzz6ET8GM5uoFtjM > BEWVUCjt8b0m50AE9z5UD38VmBJc/tyMVoJGTueVuN/W37izNASUG3jtgzx8AT0W > 3lewj+oBxKylhaQJjqDg0RerNuq0J4+ALl3Dp9k42anJr/AMTs+oc0z68j+ILXRW > sdujaw+qhgoFzNpkOeEkpGqQmkR3X4s7BBDJb/NOuLnIoVzFzTPhLlb4xIe05+WB > zzEPRiJCOesmSs/q+yClFiJj39lm7guZ0tS1/9MdZnlaeNi75Nh1DdQQjdTrkbyR > QXgZ7Ezrnng0PRugQDxw > =jE8+ > -----END PGP SIGNATURE----- > >