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

So, I'm having a bit of trouble with a simple program I've (poorly) written to find version information, etc. about various executables. An xml file is supplied containing the executable name, the command line option to find the version, and (usually) the line number of the output from the previous command on which the actual version appears. My problem is this - it works fine on my test cases of ruby and perl, but when it gets to python the output of the "python -V" command is printed to the screen instead of being taken in by the PULLINFO filehandle, and it thus does not get passes along to the rest of the program. Does anyone know why this is? I'm assuming that it has something to do with the way that python's "-V" command operates internally, but I don't really have a whole lot of understanding on the matter myself. I also assume that their are many ways to better do what I'm trying to, and I'd certainly be open to hearing about them as well (however, due to constraints at work I am unable to install modules without a good deal of difficulty). Here is a code snippet of the relevant portion:
#%executables is a hash of hashes, keyed by the executable name, and w +ithin that hash by names corresponding to the xml file - flag, versio +n, etc. #$exName is the name of the executable being dealt with in the curren +t loop iteration. open (PULLINFO, "$exName $executables{$exName}{'flag'} |") or die("bla +sted cutthroats... can't they refrain from \"$! \"-ing?"); my @versInfo = <PULLINFO>; close PULLINFO; unless($versInfo[$executables{$exName}{"opLine"}]=~ /((?:\d+)(?:\. +\d+)+)/ and $executables{$exName}{"version"}= $1) { FINDFO:foreach (@versInfo) { if(/((?:\d+)(?:\.\d+)+)/){$executables{$exName}{"version"} + = $1;last FINDFO;} } }
Any help would be much appreciated :ロ]
~~~~~~~~~~~~~~~~~~~~~~
Timshel - bloody heck yes.

Replies are listed 'Best First'.
Re: version retrieval difficulties
by shandor (Monk) on Apr 12, 2007 at 20:05 UTC

    The python -V command returns its output to STDERR instead of STDOUT, it seems. so, you probably have to have your OPEN command grab the input from STDERR... maybe like this:

    open VERSION, "python -V |", \*STDERR or die "This doesn't work at all: $!\n";
      That's cleared up what exactly is going on, thanks! Now to see what can be done about it :0)
      ~~~~~~~~~~~~~~~~~~~~~~
      Timshel - bloody heck yes.
      This doesn't work at all
      Yeah, indeed,
      $ perl -le 'open VER, "python -V |", \*STDERR or die $!; Unknown open() mode 'python -V |' at -e line 1.
      Did you even test your code?

      I usually prefer the backtick operation:

      $ perl -le 'chomp($v = qx/tar --version 2>&1/); print $v' tar (GNU tar) 1.15.1

      Update: Just for the record, tar version info goes to STDOUT.
        Did you even test your code?

        Yes, and it didn't work at all, which is why the messages. :)

        The code wasn't meant to work, but to suggest a possible place to start looking since, after quite a bit of searching, I couldn't find any references to reading from STDERR. I guess I should have put a warning in my post.

Re: version retrieval difficulties
by Snigwel (Sexton) on Apr 17, 2007 at 17:53 UTC
    Thanks a lot guys, I just changed the 'open' expression to :

    open (PULLINFO, "$exName $executables{$exName}{'flag'} 2>&1 |") or die("blasted cutthroats...  can't they refrain from \"$! \"-ing?");

    and everything works just fine!
    ~~~~~~~~~~~~~~~~~~~~~~
    Timshel - bloody heck yes.