Please login or register.

Login with username, password and session length
Advanced search  

News:

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

Pages: [1] 2

Author Topic: Command line arguments in AHP Windows commands  (Read 16970 times)

orcusomega

  • Sr. Member
  • ****
  • Helpful Post Rating: 6
  • Posts: 97
Command line arguments in AHP Windows commands
« on: January 03, 2011, 09:18:19 AM »

I am trying to implement a logging feature, but I am so far unable to find a way to pass variables to the command line.  For example, I want to have one batch file that I can use, then at execution, pass it the name, etc.

Example:
Code: [Select]
c:\Program Files\Home Monitoring\door_logger.bat front_door open

AHP won't allow me to put " in the command line, and if I simply add it to input box, it doesn't run.

I really would rather not have to create a ton of individual scripts!!!

Thanks,

Bob
Logged

troll334

  • Hero Member
  • *****
  • Helpful Post Rating: 11
  • Posts: 159
Re: Command line arguments in AHP Windows commands
« Reply #1 on: January 03, 2011, 09:47:40 AM »

Hey Bob, and Happy New Year!
The innards of your batch file would look something like this:
********************
ahcmd sendplc %1 %2
********************
where %1 would be the first argument after your batch file run
and %2 would be the second.

So you would run the batch file door_logger B1 On
and the actual command given to DOS would be
ahcmd sendplc B1 On
To log the output of ahcmd, you would need to include
>> c:\Bobs_logfile.txt
at the end of the command in the batch file. Thus, the innards
of your batch file would now read:
********************
ahcmd sendplc %1 %2 >>c:\bobs_logfile.txt
********************
after each run of the batch file, the file entitled bobs_logfile.txt
in the root of drive C would contain the output of ahcmd.
If have NOT tested this but have worked with DOS for decades

*****************************
After post...
sorry Bob,
ahcmd does not appear to output anything on the command-line. So, scratch the >> crap.
the rest of it seems to work though.
« Last Edit: January 03, 2011, 10:06:01 AM by troll334 »
Logged
AHP 3.236. CM15A. XTB-IIR. XTBM. Hauppauge 950Q.

Tuicemen

  • Administrator
  • Hero Member
  • ****
  • Helpful Post Rating: 272
  • Posts: 10111
  • I don't work for X10, I use it successfuly!
    • Tuicemen Forum
Re: Command line arguments in AHP Windows commands
« Reply #2 on: January 03, 2011, 10:05:00 AM »

troll334
Having the line ahcmd sendplc ....
will send another X10 signal which I don't think  orcusomega is trying to do!
orcusomega:
In order for your monitoring program to work
The Bat file needs the commands inside it.
I've never seen a bat file take command line arguments it send them to a EXE file
what does the inside of your Bat file look like?
PcCompanion uses bat files very successfuly from AHP
 >!
« Last Edit: January 03, 2011, 10:09:51 AM by Tuicemen »
Logged
Please Read Topic:
General Forum Etiquette
Before you post!

Find extra info @ My forum

troll334

  • Hero Member
  • *****
  • Helpful Post Rating: 11
  • Posts: 159
Re: Command line arguments in AHP Windows commands
« Reply #3 on: January 03, 2011, 10:10:02 AM »

Sorry guys,
I @$$sumed Bob was running independent of AHP...didn't put it together from the OP.  B:(
I'm out...
Logged
AHP 3.236. CM15A. XTB-IIR. XTBM. Hauppauge 950Q.

orcusomega

  • Sr. Member
  • ****
  • Helpful Post Rating: 6
  • Posts: 97
Re: Command line arguments in AHP Windows commands
« Reply #4 on: January 03, 2011, 10:20:00 AM »

Thanks all for the reply - here's the gist of it.

I want to use AHP Smart Macro to run my logger script, named "logger.bat".  In order to get the logger output the right information, I want to use a Smart Macro to run the following:

Code: [Select]
logger.bat DOOR FRONT OPEN
then capture the three command line variables and output it to a CSV file.  The goal is to have a log that looks something like this:

Code: [Select]
DATE,TIME,TYPE,LOCATION,ACTION,DESCRIPTION
2011-01-03,10:05:36,DOOR,FRONT,OPEN,Front Door was opened.
2011-01-03,10:05:41,DOOR,FRONT,CLOSE,Front Door was closed.

Hoewever, AHP does not run the command if I give it the command line paramters, and it will not allow me to put " in the field.

Here is the modified fle that has to be run per command (in other words, I need one batch file per action I want to log - GOD AWFUL.

Code: [Select]
@echo off

:: ###########################################################################
::                 X10 Command Logger
::
:: Purpose: To give the basic ability for ActiveHome to
::          log events seen in macros, etc to a CSV file
::          that can later be reviewed, edited, audited, etc
::
:: Example Use Case: Log when doors are opened, etc
::
::
:: ###########################################################################

set TYPE=GARAGE DOOR
set LOCATION=BOB
set DESCRIPTION=Bob's garage door was opened
set ACTION=OPEN
set LOGDIR=D:\\logs\\
set LOGFILE=%LOGDIR%\\home.log
set CURDATE=%date:~10,4%-%date:~4,2%-%date:~7,2%
set CURTIME=%time:~0,8%


:: ###########################################################################
:: See if the log file exists, and if not, create it and populate the headings
:: ###########################################################################

if not exist %LOGFILE% (
echo DATE,TIME,TYPE,LOCATION,ACTION,DESCRIPTION > %LOGFILE%
)


echo %CURDATE%,%CURTIME%,%TYPE%,%LOCATION%,%ACTION%,%DESCRIPTION% >> %LOGFILE%

Just realized this as I was typing, but if the script is called from a ,location that is present in the PATH variable, I wonder if it will let me do it then?

Bob
Logged

orcusomega

  • Sr. Member
  • ****
  • Helpful Post Rating: 6
  • Posts: 97
Re: Command line arguments in AHP Windows commands
« Reply #5 on: January 03, 2011, 11:14:34 AM »

Well it doesn't seem that AHP will do ANY command line parameters???

Anyone have any luck with this?  I am now using individual scripts calling the main logger with the command line parameters I need, but it is rediculous ...

Help or suggestions are appreciated!

Bob
Logged

Tuicemen

  • Administrator
  • Hero Member
  • ****
  • Helpful Post Rating: 272
  • Posts: 10111
  • I don't work for X10, I use it successfuly!
    • Tuicemen Forum
Re: Command line arguments in AHP Windows commands
« Reply #6 on: January 03, 2011, 11:31:01 AM »

What version of AHP are you using?
Logged
Please Read Topic:
General Forum Etiquette
Before you post!

Find extra info @ My forum

troll334

  • Hero Member
  • *****
  • Helpful Post Rating: 11
  • Posts: 159
Re: Command line arguments in AHP Windows commands
« Reply #7 on: January 03, 2011, 11:38:36 AM »

Yuk...
fasten your seatbelt  :)
'Execute Windows Program' to run a batch file that will simply create an empty text file named FrontDoorOpen.txt
Then execute your primary batch file (no arguments) in the same macro (probably seperated by a few-second delay).
Mod the primary batch file to look for the existence of FrontDoorOpen.txt
If exist then do your thing.
Of course, you'll also need to create a dummy file for open / close and test for it's existence.
It gets ugly, and will be quite large, but you could make this cluge work.
Logged
AHP 3.236. CM15A. XTB-IIR. XTBM. Hauppauge 950Q.

Noam

  • Community Organizer
  • Hero Member
  • ***
  • Helpful Post Rating: 49
  • Posts: 2805
Re: Command line arguments in AHP Windows commands
« Reply #8 on: January 03, 2011, 12:36:11 PM »

Isn't that still creating an individual script for each and every trigger?
It would be better if the programmers gave us the ability to run a command with parameters.
Logged

troll334

  • Hero Member
  • *****
  • Helpful Post Rating: 11
  • Posts: 159
Re: Command line arguments in AHP Windows commands
« Reply #9 on: January 03, 2011, 01:18:26 PM »

hmmmm,
don't think so. If I am now understanding correctly, Bob would be creating a macro for each of the
callable events. Each macro would contain it's own unique calls which would have unique parms to pass.
My goofy solution merely replaces his parameters with the additional precursor that would create a dummy file(s)
which the primary batch file would test for and act upon accordingly.
Granted, this solution WILL require better-than-average knowledge of MS-DOS batch scripting. But it's do-able.
Your idea of a programmer providing us with parms to pass is, quite simply, elegant. I'm not certain I would wait
on that mod.
Logged
AHP 3.236. CM15A. XTB-IIR. XTBM. Hauppauge 950Q.

orcusomega

  • Sr. Member
  • ****
  • Helpful Post Rating: 6
  • Posts: 97
Re: Command line arguments in AHP Windows commands
« Reply #10 on: January 03, 2011, 01:58:30 PM »

Here's what I had to do in the end.  I used two files, one is "logger.bat" that contains all the heavy lifting, then for each command I want to log, I had to create a "door-open.bat" or "door-close.bat" to get the info to the logger.bat file.

Say what?  Here's what it looks like:

Macro trips, and is configured to run a specific batch file.  In this case it is front_door-OPEN.bat which contains:

Code: [Select]
@echo off
call logger.bat DOOR FRONT OPEN "The Front door was opened"

This is basically a shim to take the command line variables and pass them to logger.bat, since AHP can't do it.

Why?  Isn't this more work?

Well, yes it is, but if I want to change where the logs go, the name, blah blah blah, I would need to change every single batch file.  This way I would only need to change logger.bat and it would update the actions of everything.  I have commented it heavily so that folks other than myself can use it I hope!

For those of you interested, here is the logger.bat file:

Code: [Select]
@echo off

:: ###########################################################################
::                 X10 Command Logger
::
:: Author: Bob Perciaccante (bob@perciaccante.net)
:: Purpose: To give the basic ability for ActiveHome to
::          log events seen in macros, etc to a CSV file
::          that can later be reviewed, edited, audited, etc
::
:: Example Use Case: Log when doors are opened, etc
::
::
:: ###########################################################################

:: ###########################################################################
:: Take the command line options and assign them to the basic variables.
:: Usage: logger.bat [option 1] [option 2] [option 3] [option 4]
::    Option 1: Contents assigned to Field1
::    Option 2: Contents assigned to Field2
::    Option 3: Contents assigned to Field3
::    Option 4: Contents assigned to Field4
:: ###########################################################################

set FIELD1_VAR=%1
set FIELD2_VAR=%2
set FIELD3_VAR=%3
set FIELD4_VAR=%4

:: ###########################################################################
::  Define basic parameters.
::   LOGDIR: The output directory you want the log to be placed in.
::   LOGFILE: The name of the output file
::   DELIMETER: The character you want to seperate fields with in the log.
:: ###########################################################################

set LOGDIR=D:\\logs\\
set LOGFILE=%LOGDIR%\\home.log_new
set DELIMETER=,

:: ###########################################################################
::  Define how date and time formatting will be handled
:: ###########################################################################

set CURDATE=%date:~10,4%-%date:~4,2%-%date:~7,2%
set CURTIME=%time:~0,8%

:: ###########################################################################
::  Output format is currently 6 columns.
::    COLx_LABEL: This is the heading line of the log file, name the
::                  columns here
::
:: ###########################################################################

set COL1_LABEL=DATE
set COL2_LABEL=TIME
set COL3_LABEL=TYPE
set COL4_LABEL=LOCATION
set COL5_LABEL=ACTION
set COL6_LABEL=DESCRIPTION

:: ###########################################################################
:: See if the log file exists, and if not, create it and populate the headings
:: ###########################################################################

if not exist %LOGFILE% (
echo %COL1_LABEL%%DELIMETER%%COL2_LABEL%%DELIMETER%%COL3_LABEL%%DELIMETER%%COL4_LABEL%%DELIMETER%%COL5_LABEL%%DELIMETER%%COL6_LABEL% > %LOGFILE%
)

:: ###########################################################################
::  Take all the variables assigned above and decide the order you want
::    them to be entered in the log
:: ###########################################################################

set COL1=%CURDATE%
set COL2=%CURTIME%
set COL3=%FIELD1_VAR%
set COL4=%FIELD2_VAR%
set COL5=%FIELD3_VAR%
set COL6=%FIELD4_VAR%

:: ###########################################################################
::  Take the information and write it to the log file.
:: ###########################################################################

echo %COL1%%DELIMETER%%COL2%%DELIMETER%%COL3%%DELIMETER%%COL4%%DELIMETER%%COL5%%DELIMETER%%COL6% >> %LOGFILE%

The field names are configurable, as are the delimeters.  In this case, the output of the above door-open.bat and logger.bat gives you this logfile:

Code: [Select]
DATE,TIME,TYPE,LOCATION,ACTION,DESCRIPTION
2011-01-03,14:02:08,DOOR,FRONT,OPEN,"The Front door was opened"


Hope this helps,

Bob
« Last Edit: January 03, 2011, 02:04:04 PM by orcusomega »
Logged

troll334

  • Hero Member
  • *****
  • Helpful Post Rating: 11
  • Posts: 159
Re: Command line arguments in AHP Windows commands
« Reply #11 on: January 03, 2011, 02:03:28 PM »

You gotta 'helpful' from me on that one. Bravo! Much cleaner than my junk and likely quicker runtime
since you won't be creating/deleting dummy files on a slow harddrive.
 #:)
Logged
AHP 3.236. CM15A. XTB-IIR. XTBM. Hauppauge 950Q.

orcusomega

  • Sr. Member
  • ****
  • Helpful Post Rating: 6
  • Posts: 97
Re: Command line arguments in AHP Windows commands
« Reply #12 on: January 03, 2011, 02:08:16 PM »

Thanks!  I know there is a little redundancy in taking %1 and assigning it to another variable, but it should make it easier for a non-batch programmer to understand, I hope!

I'm working on an improved email script that will work along the same lines, should give folks a lot mor flexibility, especially since I can't get my email scripting to work at all.. grrrr

Bob
Logged

Noam

  • Community Organizer
  • Hero Member
  • ***
  • Helpful Post Rating: 49
  • Posts: 2805
Re: Command line arguments in AHP Windows commands
« Reply #13 on: January 03, 2011, 02:59:53 PM »

Well, maybe now that the holidays are over, one of the developers will chime in here, about the possibility of fixing the "windows command" function to allow command line parameters.
Logged

erlwebmail

  • Jr. Member
  • **
  • Helpful Post Rating: 0
  • Posts: 11
Re: Command line arguments in AHP Windows commands
« Reply #14 on: January 12, 2011, 02:38:17 PM »

Duh...  Worked great once I realized that I couldn't bury it all in my "My Documents" sub-directory. :o I put the call, avoiding any quote marks,    C:\X-10-tools\logger--test-cmd.bat      in an Execute Windows Program block in the macro, stuck the batch files in a new    C:\X-10-tools    directory, and it worked great.
Many thanks, and see you further down the learning curve. #:)
Logged
Pages: [1] 2
 

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