Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Here's the call:

$datepos = system ("rexx", "fmtscan.rex", "$fn", "$datefieldname", "P" +)/256;
I have used the debugger to confirm that the parameters are correct at this point in the perl script, and I have confirmed that the REXX script I'm calling is returning the correct value.
What I want is 303, but what I get is 47.

The highest value the program will properly return is 255, which leads me to think that only two bytes (since it get divided by 256) is used for the return value, which reverts to zero once 256 is reached.

Also 303-47 = 256

Assuming this is correct, I suppose I have two distinct questions:

  1. How could I capture a return value from a system() call that is greater than 255?
  2. Why does system() return the proper value multiplied by 256 anyway? Is that an insurmountable consequence of the architecture? It just seems to serve no purpose at all...
Problem that shouldn't exist don't challenge me so much as they just piss me off.

Although I am running NT4.. (grumble,complain)

Any thoughts?

==
PiEquals3, whose web-based (ackthpt!) email service went down and left him unable to access his cryptic login password.. :(
==

Replies are listed 'Best First'.
Re: Annoying system() limitations
by runrig (Abbot) on Jan 17, 2001 at 23:24 UTC
    Perhaps you should look at Why can't I get the output of a command with system()?

    Ok maybe that's not so helpful, and maybe NT can return more than a seven bit return code (I don't know), but I ran this on Unix:
    perl -e 'exit 304' || echo $? # and for the fun of it: awk 'BEGIN {exit 304}' || echo $?
    and it printed '48' in both cases so there is definitely a 7 bit limitation here.
      Hrm..

      Well that's frustrating.. I'm not sure what to do about this..

      Some ideas:

      • Redirect the output to a file; read the file .(e.g.,
        system("$program $paramlist > file.txt");
        This might work in the general case, but this particular REXX script ("fmtscan()")I'm calling doesn't generate output. It only returns a value. I couldn't change that without breaking all the REXX programs that call it.

      • Change fmtscan() to return a string instead of a numeric value. This would work fine since everything is a string in REXX, and it seems there must be a way to do that in Perl... but I don't know what that way is.

      • Rewrite fmtscan() in Perl, itself! Sounds fun, sounds like a learning experience... sounds like I'll finally have to learn to build a module. About damn time, I say.
        Check perlman:perlop for the qx operator (way at the end under "quote-like" stuff). This may do what you want.