in reply to Re: How to get output from a forked cmd prompt?
in thread How to get output from a spawned cmd prompt?

Follwoing is the o/p:
SV = PVMG(0x9b2e8c) at 0x9b9d3c REFCNT = 1 FLAGS = (GMG,SMG) IV = 0 NV = 0 PV = 0 MAGIC = 0x9c4f5c MG_VIRTUAL = &PL_vtbl_sv MG_TYPE = PERL_MAGIC_sv(\0) MG_OBJ = 0x9b9d2c MG_LEN = 1 MG_PTR = 0x9c4f8c "?"

Replies are listed 'Best First'.
Re^3: How to get output from a forked cmd prompt?
by ikegami (Patriarch) on Jan 21, 2010 at 20:16 UTC

    Me bad. That should have been

    use Devel::Peek; 1 if $?; # mg_get Dump($?);

    But don't bother. The only way only what you said could happen is if system and $? are not returning the same thing like they are suppose to. I could ask you to show me a dump of both to confirm that or to show that what you said is wrong. Neither outcome would be productive.

    Since there's no reason to check both, pick one. (See snippets below.) If you then have problems with it containing the wrong value, we'll investigate why it has the wrong value then, knowing what value is obtained and what the value should be.

    system($cmd); if ($? == -1) { die("Can't execute command: $!\n"); } elsif ($? & 127) { die("Command died from signal ", ($? & 127), "\n"); } elsif ($? >> 8) { die("Command exited with error ", ($? >> 8), "\n"); }
    or
    my $rv = system($cmd); if ($rv == -1) { die("Can't execute command: $!\n"); } elsif ($rv & 127) { die("Command died from signal ", ($rv & 127), "\n"); } elsif ($rv >> 8) { die("Command exited with error ", ($rv >> 8), "\n"); }

    By the way, make sure you aren't using system and fork in the same program.