in reply to capturing error messages from backticks or system

I think that your problem is that the "english readable" error isn't being produced by "net". It's comming from someplace else (the OS). If you redirect STDERR, you'll see that STDERR from the call to net is not the "english readable" message. I'm testing this on 2000, so I can't verify the results on NT. Here's my results.
#!/usr/bin/perl -w use strict; my $results = `net use f: \\\\SERVER\\c\$ 2>&1`; print "results contains - $results\n";
results -
C:\dev>map.pl results contains - System error 1202 has occurred. An attempt was made to remember a device that had previously been reme +mbered.
On NT, your whole error message may be in STDERR. It's not in 2000 though.

Hope this helps..
Rich

update: I'm an idiot. The entire message is in $results. So forget I mentioned that the whole thing wasn't sent to STDERR. I assumed it wasn't because of the new lines. I guess that's what I get for thinking! :)

Replies are listed 'Best First'.
(tye)Re: capturing error messages from backticks or system
by tye (Sage) on Aug 28, 2001 at 23:43 UTC

    Your test code isn't conclusive. Since you don't have a clear ending delimiter in your print statement, we can't tell whether the "An attempt..." string is part of $results or not.

    Fixing that:

    #!/usr/bin/perl -w use strict; my $results = `net use f: \\\\SERVER\\c\$ 2>&1`; print "results contains ($results)\n";
    gives me this:
    results contains (System error 67 has occurred. The network name cannot be found. )
    on Win2K. So the error message is going to STDERR, even in Win2K.

    For capturing STDERR, IPC::Open2 and IPC::Open3 are often good alternatives.

            - tye (but my friends call me "Tye")