Alternative to flaky ahcmd.exe

Started by dbemowsk, March 16, 2010, 01:05:54 AM

Previous topic - Next topic

dbemowsk

OK, by the advice of tuicemen, I am working on an alternative solution to the ahcmd.exe that uses the ahscript.dll.  Here is what I came up with


Dim ActiveHomeObjDim OutputSet ActiveHomeObj = CreateObject("X10.ActiveHome")Output = ""Sub parseArgs()    Dim objArgs    If (WScript.Arguments.count < 3) Then        WScript.Echo "Incorrect number of arguments passed to the script"    Else        Output = ActiveHomeObj.SendAction(WScript.Arguments(0), WScript.Arguments(1) & " " & WScript.Arguments(2))        While Output = ""        Wend        WScript.Echo Output    End IfEnd SubCall parseArgs()?>



First thing is that my VB is quite rusty, and although this works, it may not be correctly coded.  If anyone can make suggestions for changes to this it would be appreciated. 

Next, I am using this as a VBScript and calling it from my PHP app.  The issue is that when I run it using the function below, it is significantly slower than using ahcmd.exe.


    function x10cmd($type, $hcode, $ucode, $action, $time="") {        $cmd = $type." ".$hcode.$ucode." ".$action." ".$time;        exec("CScript .\bin\ahscript.vbs ".$cmd, $returnVal, $na);        $return = (isset($returnVal[3])) ? (INT) trim($returnVal[3]) : $returnVal;        }        return $return;    } //End function x10cmd?>



the reason it is slower is because the variable $returnVal gets populated as an array like this:


            [0] => Microsoft (R) Windows Script Host Version 5.7            [1] => Copyright (C) Microsoft Corporation. All rights reserved.            [2] =>             [3] => 1?>



Every time I make a call to the function it has to dump val 0, val 1, and val 2 from the array to get val 3 which is the information I need.  What I am wondering is is it possible to set the WSH CScript engine to a less verbose output that only gives me val 3 for the output?  If not,  can my VBScript be compiled into an executable that only returns the value of val 3?  I have tried the //B option when running the script, but then I do not get any output.

[update] ... Ok, I just tried the //Nologo option and it does only give me the above [3] value, which is faster, but I still think it would be slightly faster with a compiled executable.  Input on this is still appreciated.

Many thanks in advance to anyone that can help me in this dilema.

Dan Bemowski
Dan Bemowski
Owner of PHP Web Scripting LLC
Programmer of RemoteWatch X10
User of any X10 products I can get my hands on.