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

Hi,

I am quite new to perl. I have adapted a perl radius script to work within Solarwinds APM. (A windows program)

However Solarwinds APM requires a $WScript->Quit(x); x = either 0,1,2,3,4,5 which corresponds to a status type.

The script runs correctly without any of the WScript lines however when run it the WScript it runs with the following error.

C:\Perl Scripts\RadiusPerl-0.12\Authen-Radius-0.12>perl test5.pl Message:Success Statistic:0 Can't call method "Quit" on an undefined value at test5.pl line x.

i have seen some online references to use WScript;

But cannot find any modules with this name. Does anyone have any advice.

Regards

Miron

****************************************

use Authen::Radius; $r = new Authen::Radius(Host => "xxx.xxx.xxx.xxx:1812", Secret => "xxx +x"); $s = $r->check_pwd("monitor", "xxxx"); if ($s == 1) { print "Message:Success \n"; print "Statistic:0 \n"; $WScript->Quit(0); } else { print "Message:Failure \n"; print "Statistic:1 \n"; $WScript->Quit(1); } exit 0;

Replies are listed 'Best First'.
Re: WScript Win32
by NetWallah (Canon) on Dec 14, 2008 at 19:00 UTC
    Wscript is a Microsoft Windows scripting engine object - the examples you are attempting to re-implement in perl probably use VBScript.

    You should "use strict;" in your perl code - this would have told you the $WScript is undefined, and in this case, unnecessary.

    The function the original code appears to be trying to do is implemented in perl via the "exit" built-in function.

    Update:s/sctrict/strict/ (Thanks FunkyMonk)

         ..to maintain is to slowly feel your soul, sanity and sentience ebb away as you become one with the Evil.

Re: WScript Win32
by jand (Friar) on Dec 15, 2008 at 06:59 UTC
    The $WScript variable is only defined when your code is executed inside the Windows Scripting Host. You can run your script inside WSH by using the .pls extension for your script and running it as wscript test5.pls.

    Note that WSH support for Perl requires the PerlScript ActiveX scripting engine interface from ActivePerl and is not available with other Perl distributions.

      Hi,

      Thanks for your responses before. I have tried to gather some more information so that I can change the question into something more intelligent:-)

      Basically if i run the following two tests from the command line:

      *********TEST1**********

      cscript //E:PerlScript c:\"Perl Code"\test1.pl

      #code from test1.pl

      print "Hello";

      WScript->Quit(2)

      I will receive the following output.

      Hello

      (check error code)

      c:\ echo %ERRORLEVEL%

      2 (Response)

      *********TEST2**********

      cscript //E:PerlScript c:\"Perl Code"\test2.pl

      code from test2.pl is shown in original post

      I will receive the following output:

      Message: Success

      Statistic: 0

      Server Teminated Script.

      (check error code)

      c:\ echo %ERRORLEVEL%

      -1073741785 (response)

      *******************************

      So then my question is what causes the script to terminate with that error code. From what I can see if i remove the statements which refer to the sub modules within radius.pm the script does not return that error code. Im sure i am doing something obviously wrong. Does anyone know what I should be doing.

      Kind Regards

      Miron