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

Hello visionaries, I am using ActiveState on WinXP (perl 5.8.0). I am trying to call a batch file which in turn calls an executable using backtick. The batch file looks at "errorlevel" and then echos some string base on errorlevel. I then assign a variable to the return of the backtick. I am having weird problems when porting this script. It works fine on XP. On windows 95 instead of returning the echoed string to Perl the batch file prints it in the command window and my variable comes up empty. This behavior occurs on both operating systems when I use system instead of backtick. The executable I am calling determines what Windows OS it is running on. If there is a handy Perl module that does the same it would alleviate my whole problem.

Replies are listed 'Best First'.
Re: Backtick Windows Problems
by robartes (Priest) on Feb 06, 2003 at 23:30 UTC
    Why do you need the batchfile between your Perl script and the executable? The system call returns the exit status of whatever is executed, so you could use that to grab the exit status (or error level) of your executable (if that is actually what you want to do). Please note that you need to shift the return value of system 8 bits to the right to get the actual exit status:
    my $status=system($executable); print "Exit value was: ".$status>>8;

    CU
    Robartes-

Re: Backtick Windows Problems
by AcidHawk (Vicar) on Feb 07, 2003 at 06:07 UTC

    If you are only looking to identify what version of windows you are running have a look at Windows Version Detection or Which flavor of Win32? there is some nice code there also.

    -----
    Of all the things I've lost in my life, its my mind I miss the most.