Please login or register.

Login with username, password and session length
Advanced search  

News:

The X10Hub (PiX10Hub) is here! Created by the Community, for the Community.:)% #:)

Author Topic: Alternative to flaky ahcmd.exe  (Read 4408 times)

dbemowsk

  • Hero Member
  • *****
  • Helpful Post Rating: 21
  • Posts: 428
    • PHP Web Scripting
Alternative to flaky ahcmd.exe
« on: March 16, 2010, 01:05:54 AM »

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 ActiveHomeObj
Dim Output

Set ActiveHomeObj 
CreateObject("X10.ActiveHome")
Output ""

Sub parseArgs()
    
Dim objArgs

    
If (WScript.Arguments.count 3Then
        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 
If
End Sub

Call 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 (RWindows Script Host Version 5.7
            
[1] => Copyright (CMicrosoft CorporationAll 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
« Last Edit: March 16, 2010, 01:54:14 AM by dbemowsk »
Logged
Dan Bemowski
Owner of PHP Web Scripting LLC
Programmer of RemoteWatch X10
User of any X10 products I can get my hands on.
 

X10.com | About X10 | X10 Security Systems | Cameras| Package Deals
© Copyright 2014-2016 X10.com All rights reserved.