[EMAIL PROTECTED] writes:
> However if I try my own code ( bwtest::spawn simply spawns the command
> ,puts the output to a file and returns the pid)
> the first java class returns zero (0) as the VMS exit status and the 2nd
> One (1)
>
> use vmsish qw(status);
> use bwtest;
> $pid= bwtest::spawn("java \"demos.dynany.Server\"","t.log");
> waitpid($pid,0);
> print "** $?**\n";

It matters how you create the subprocess, and this is arguably exercising
buggy/inconsistent code.

The main (only?) ways to run a subprocess from Perl are:

1        system('stuff');        # system() call
2        `stuff`;                # backticks
3        open(FOO,'|stuff');     # piped i/o

for 2 and 3, the piped i/o routines are used; they have the proper
handling of return status and waitpid (and 'close()') sets $? correctly.

But when I wrote the piping code, I didn't touch system() at all.  That
seemed like a good idea at the time, but now it's clear that system()
needs to change to play well with waitpid and $?.

As an immediate workaround, try using open(FOO,'|yourstuff')  or
open(FOO,'yourstuff|'), whichever fits best with what you're trying to
do.

Longer term, I'm going to have to do some more hacking on the code.
What I have in mind is changing safe_popen to call a more general
routine, something like:

    spawn_sub(command, input_filehandle, output_filehandle, err_filehandle)

that can deal with all combinations of filehandles being active or null.

    spawn_sub(command, null, null, null)  -> system('command')
    spawn_sub(command, in, null, null)    -> open(in,'|command')
    spawn_sub(command, null, out, null)   -> open(out,'command|')
    spawn_sub(command, in, out, err)      -> open3

The code for piped i/o will stay pretty much the same in how it works,
but system() would change, and there would be the possibility of
implementing open3...

It'll probably take me a few weeks to get working patches out.  Now
would be a good time to make suggestions for changes.
--
 Drexel University       \V                    --Chuck Lane
======]---------->--------*------------<-------[===========
     (215) 895-1545     _/ \  Particle Physics
FAX: (215) 895-5934     /\ /~~~~~~~~~~~        [EMAIL PROTECTED]

Reply via email to