Please login or register.

Login with username, password and session length
Pages: [1] 2

Author Topic: Running a windows program from a macro and passing an argument  (Read 32252 times)

jawaid

  • Sr. Member
  • ****
  • Helpful Post Rating: 1
  • Posts: 84

I would like to run a windows program from the macro. This is easy to do by using the 'Execute Windows Program' function and specifying the path of the program to run on the PC. This works OK, but the problem is that it does not seem to pass the arguments to the program. Has anyone tried this feature? Any suggestions will be very welcome.

Thanks.
Logged

Noam

  • Community Organizer
  • Hero Member
  • ***
  • Helpful Post Rating: 51
  • Posts: 2818
Re: Running a windows program from a macro and passing an argument
« Reply #1 on: July 21, 2006, 09:11:02 AM »

What about putting the program name and arguments into a .bat or .cmd file, and running that?
Logged

jawaid

  • Sr. Member
  • ****
  • Helpful Post Rating: 1
  • Posts: 84
Re: Running a windows program from a macro and passing an argument
« Reply #2 on: July 24, 2006, 02:50:40 AM »

Noam

That is what I ended up doing - create a .bat file for each situation and putting the arguments there. I also tried to put the entire command including the arguments in single or double quaotes in the macro but it did not work.
Logged

Biker

  • Jr. Member
  • **
  • Helpful Post Rating: 4
  • Posts: 16
Re: Running a windows program from a macro and passing an argument
« Reply #3 on: July 28, 2006, 08:41:34 AM »

The SMART MACRO editor is quirky at best. I wrote a program to use speech synthesis. The arguments are the thing to say. I browsed the EXE I made, and it looked something like this:

EXECUTE WINDOWS PROGRAM
D:\....\Say.exe "The security alarm will be armed in 90 seconds. Please exit at once."

When you look below in the textual form of the macro, the parameter is NOT shown. Click away from the EXECUTE box, still it does not show. If I simply CLICK in the textual form window, the parameter suddenly appears in the textual form window. QUIRKY, but it works.

I can live with that. Here is my problem...

Now I add a 30 second delay to the macro and add another one..

EXECUTE WINDOWS PROGRAM
D:\....\Say.exe "The security alarm will be armed in 60 seconds. Please exit at once."

I do the click trick to get the parameter INTO  the textual form of the MACRO, and indeed the second EXECUTE has the 60 second warning. THE PROBLEM is that the FIRST EXECUTE parameter has ALSO been changed to the 60 second warning!  APPARENTLY you can not have multiple EXECUTEs in the same MACRO with differing command line parameters. This is most definitely a show-stopper bug for which I can find no work-around, as is the less serious need for the click trick.
Logged

Biker

  • Jr. Member
  • **
  • Helpful Post Rating: 4
  • Posts: 16
Re: Running a windows program from a macro and passing an argument
« Reply #4 on: July 28, 2006, 09:45:16 AM »

The problem seems to be that AHP/SmartMacro developers are confused about how XML works. You can see what is going on by looking at the MyHome.ahx file after editing. I see TWO problems. One is very clearly a bug in the Smart Macros editor, and the other is more of a fundamental confusion about XML.

1) When editing a macro and adding an EXECUTE command, the commands are stored in what is called a USER ELEMENT. These are assigned ID numbers. The first is assigned 101. The second is assigned 102. The two USER ELEMENTS are indeed created with those ID numbers. But if you look back at the reference to the user element where the EXECUTE command is stored, if there is more than one EXECUTE command, they are BOTH attributed to 102. Where what SHOULD be happening is the first EXECUTE should be attributed to 101, and the second one is attributed to 102.

2) While it appears the MyHome.ahx is intended to be XML-like, it is not. The rules seem to vary slightly. The data for each element is stored in a quoted string. But AHP seems to have no way of representing double quotes within the data. If this were TRUE XML, it would be using something called ENTITIES to represent certain kinds of characters that are themselves part of the XML syntax. An example is the double quote itself, which is used to delimit the text for data associated with an attribute. For example
< tag attr="this is the data" />
As you can see, if you have a double quote as part of the data, it confuses delimitation of the text data
< tag attr="this data " contains a double quote between data and contains" />
The industry answer is to use something called "entities". Entities are essentially a way to place a special character within textual data. For example &quot; means double quote. From the earlier example, this would look like:
< tag attr="this data &quot; contains a double quote between data and contains" />
The XML writer must be smart enough to translate these "escapes" when writing the file, and the reader must be smart enough to translate them back when reading.

If AHP were implemented upon Microsoft XML, then this would not be a problem. AHP decided INSTEAD to develop their own, but it is NOT implemented correctly, and obviously has problems representing anything a user can enter into the AHP program.

Another demonstration of the VERY SAME problem. Create a new room. Make the name be
This is my "test room"
Save, and exit AHP.
Start AHP again, and look at the room list. The room's name has changed to
This is my

This is pretty basic stuff when using XML, so this really needs to be fixed, and should be a simple thing to do. The XML parsers and writers need to consider ALL characters that should be escaped, not just double quotes. Or else the AHP application should prevent entry of text that would interfere with XML parsing.  I have written XML parsers/writers myself, and it is not difficult. We just need to get someone's attention to fix it.

Once corrected THEN you will be able to use EXECUTE and add parameters in a quoted string after the path to the EXE file.

Once the user-element ID confusion is corrected, then you should be able to have multiple (yet different) EXECUTE commands in a single macro.

Let's hope AHP developers see this and will make the corrections for us in the next release, which I hope is soon. I have several uses for EXECUTE commands, and as is, without the ability to use several per macro, and without the ability to specify arguments, it is about as close to useless as it can be.
Logged

jawaid

  • Sr. Member
  • ****
  • Helpful Post Rating: 1
  • Posts: 84
Re: Running a windows program from a macro and passing an argument
« Reply #5 on: July 28, 2006, 11:52:00 AM »

Biker,

Very interesting. Thanks for digging into it. The editor is very quirky. I was thinking of making modifications to the ahx file and will try it to see if that would work. I just tried to add another macro to test the Windows command. Even though the command shows both on the GUI and textual displays of the editor but is not being executed at all.
Logged

jawaid

  • Sr. Member
  • ****
  • Helpful Post Rating: 1
  • Posts: 84
Re: Running a windows program from a macro and passing an argument
« Reply #6 on: July 29, 2006, 12:12:42 PM »


I ran some more tests this morning. The .ahx file does save the arguments, but as you pointed out, an argument in double quotes  presents a problem. Further, even though the argument is saved I do not see it passed on to the program invoked. At times, the command invoked with an argument does not get executed at all. Perhaps someone from X10 can shed some light here??
Logged

Biker

  • Jr. Member
  • **
  • Helpful Post Rating: 4
  • Posts: 16
Re: Running a windows program from a macro and passing an argument
« Reply #7 on: July 29, 2006, 03:22:42 PM »

The issue is if the AHX goes through a SAVE and a LOAD. If you run AHP, and put in the arguments portion within a single set of double quotes, I can verify they DO make it to the command line. The problem is when you exit AHP, it saves the macros in XML, and when you start AHP it loads them. In that process, the arguments are gone. So long as you can keep the one AHP session open, and never exit the program, it works. As soon as you start AHP again, you will see the argument (in double quotes) is gone. If you don't put the argument in double quotes, they won't make it to your application. This is a function of the process creation routine in AHP. I have written applications which spawn processes (a batch processor), and I have taken an argument similar to the one in EXECUTE command, where both the EXE path and command line arguments are in a single string, and it requires a bit of finess to get it to work without requiring double quotes.

That being said, I have ALSO found where there seems to be a residual on failed EXECUTE commands. If you don't form the command and arguments correctly, the first time in an AHP session, then it seems to remember the wrong form of the command. Try this 1) Reboot (to be sure no ghost process of your command are still running), 2) Start AHP 3) Create your EXECUTE command in the macro by a) browse to the EXE b) in the box where the EXE path is go to the end of the command line, and add a single space, a double quote, any number of arguments, and finish with a closing double quote. 4) trigger the macro. IT WORKS!  Exit AHP and restart it.  The command arguments are GONE, and it no longer works. ALSO, be sure you only have ONE EXECUTE COMMAND ANYWHERE, because if you have multiple EXECUTE commands, they all will have the same value.
Logged

jawaid

  • Sr. Member
  • ****
  • Helpful Post Rating: 1
  • Posts: 84
Re: Running a windows program from a macro and passing an argument
« Reply #8 on: July 29, 2006, 09:45:02 PM »

I have not seen any argument make it to the PC program invoked. I will try to use a signle quote. What I consistently saw this morning is that when I put in a single quote the program specified will not get invoked at all. Can you verify that you can indeed pass a single srgument to the program?

What I ended up doing is to make a .bat file which is invoked from the Smart Macros. The .bat file then calls the program needed with the right arguments. This means having a bat file for every commbination of arguments that may be needed.
Logged

Biker

  • Jr. Member
  • **
  • Helpful Post Rating: 4
  • Posts: 16
Re: Running a windows program from a macro and passing an argument
« Reply #9 on: July 30, 2006, 02:01:53 AM »

No matter how many arguments are specified they must all be in a single double quoted string:

d:\program files\...\Say.exe "This is what I want it to say"

This passes 8 parameters to my application.  With no parameters it runs the EXE. With parameters it won't even run the EXE unless all parameters are in a single double quoted string. Again, since you can't save this, and restart AHP, it only works until the AHP program is restarted. A bit of a catch-22.
Logged

jawaid

  • Sr. Member
  • ****
  • Helpful Post Rating: 1
  • Posts: 84
Re: Running a windows program from a macro and passing an argument
« Reply #10 on: July 30, 2006, 09:16:52 AM »

Biker, I am seeing a different problem. When I put in a single-quoted arguments, it refuses to execute the command What is interesting is that I was just able to save the file with a macro which had a command with 8 arguments. After that I exited AHP and restarted it. It was able to retrieve all 8 arguments and when I check the ahx file, they are still there. But once I add any arguments (even a single one) I am not able to run the command at all. In your case, you are able to run the commands but not able to save it. I am running AHP 3.204. What is your version?
Logged

Biker

  • Jr. Member
  • **
  • Helpful Post Rating: 4
  • Posts: 16
Re: Running a windows program from a macro and passing an argument
« Reply #11 on: July 30, 2006, 09:40:40 AM »

I am running 3.204 AHP, and also 3.204 Smart Macros. This may also be influenced by the OS version. I am running XP Pro SP2.

Also, you may want to double check the TEXTUAL representation of the command shown in the macro editor. I would not trust the graphical display of it above, with the little box showing the command. Also, remember, if there is more than ONE EXECUTE command the editor confuses them, and cross wires them. For me if I have two EXECUTE commands on one macro, they both are the same. ALSO, when editing that value in the EXECUTE command, the editor does not take always, and to really see what you have, you must click the window with the TEXTUAL representation, and you will notice the command displayed there will change then.

Can you give me an example of the exact syntax you used to pass 8 parameters without double quotes? I haven't been able to make that one happen at all.

It really will be nice when it gets fixed.
Logged

jawaid

  • Sr. Member
  • ****
  • Helpful Post Rating: 1
  • Posts: 84
Re: Running a windows program from a macro and passing an argument
« Reply #12 on: July 30, 2006, 07:32:27 PM »

I am running the same versions of AHP and SmartMacros as you. I am running XP Media Center Edition 2002.

I am checking the textual contents of the macro, and I also check what is saved in the ahx file.

The text content of the Test Macro is:

Turn Plant Light ON
WAIT for 1 second
Run Program - C:\JA\bin\testMacro.bat 'arg1 arg2 arg3 arg4 arg5 arg6 arg7 arg8'
Turn Plant Light OFF

I just verified again that after restarting AHP, the above macro is still there along with the arguments provided.

What I am seeing is that when I put in a single argument, the testMacro.bat does not get executed at all almost as if it aborts. The light goes off indicating teh completion of the macro.
Logged

jawaid

  • Sr. Member
  • ****
  • Helpful Post Rating: 1
  • Posts: 84
Re: Running a windows program from a macro and passing an argument
« Reply #13 on: July 30, 2006, 07:58:48 PM »

Biker, I ran one more test and modified the macro I put in my last post. I put in 3 EXECUTE statements in the following order:

Run Program - C:\JA\bin\testMacro.bat
Run Program - C:\JA\bin\testMacro.bat 'arg1 arg2 arg3 arg4 arg5 arg6 arg7 arg8'
Run Program - C:\JA\bin\testMacro2.bat

While teh second program with arguments is still showing in the GUI, the text content display dows not show the contents. The third entry displays fine.

On checking the ahx file, I see that the testMaxco.bat is saved only as one user data element but a different element has been created for testMacro2.bat.

It seems that the application only allows one user data elemnt for each unique command or executable. But it does allow multiple executables within the same macro. It saves fine as long as they are different command names.

In your case, you can create a different bat file for each set of arguments.
Logged

jawaid

  • Sr. Member
  • ****
  • Helpful Post Rating: 1
  • Posts: 84
Re: Running a windows program from a macro and passing an argument
« Reply #14 on: July 30, 2006, 08:11:35 PM »

Biker,

I did one more test. After observing that teh application saves each command as one user element regardless of how many times it is used in the macro with different arguments, I went ahead and modified the ahx file and created a separate el id in the userdata section.

      <el id="110" usage="Location" t="C:\JA\bin\testMacro.bat" />
      <el id="111" usage="Location" t="C:\JA\bin\testMacro.bat 'arg1 arg2 arg3 arg4'" />
      <el id="112" usage="Location" t="C:\JA\bin\testMacro2.bat" />

I also modified the macro in the ahx file so it refers to these el id's appropriately. The macro lines look like this:

<el cmd="19" cmdval="1" cmdtype="1" data="16" transmit="0" level="0" area="9" target="-1" uelem="110" reqpc="1" />
<el cmd="19" cmdval="1" cmdtype="1" data="16" transmit="0" level="0" area="9" target="-1" uelem="111" reqpc="1" />
<el cmd="19" cmdval="1" cmdtype="1" data="16" transmit="0" level="0" area="9" target="-1" uelem="112" reqpc="1" />

Once I did this, I was able to restart the AHP multiple times without losing the data.

The application needs a bit of manual nudging when it comes to invoking the same executable with different arguments.

I am still stuck with the problem that when I pass an argument the executable is simply not run and is just passed over.
Logged
Pages: [1] 2
 

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