PDA

View Full Version : Macro containing brackets


wellilein
07-13-2010, 07:56 AM
I have recorded the output of a build step (namely the VMWare list processes action). The output of this step contains brackets for one of the processes ([System process]) and is multiline (one process per line).

I would like to check whether a specific process is running, so I perform additional operations on the macro value. However, I can't get it work. In this simplified example I am looking for svchost in the list of running processes. Instead of a temporarily assigned macro I use a fixed project macro to reproduce.


Approach 1: Simply use the Instr() VBScript function.
[Instr(1, "%VMPROCESSES%", "svchost")]

This fails due to an unterminated string because the macro is expanded immediately, resulting in a new line. That's clear.


Approach 2: Use Application.ExpandMacros
[Application.ExpandMacros("%VMPROCESSES%")]

This of course has the same issue and I need to use double % signs to pass %VMPROCESSES% as a string to be expanded later by the method.


Approach 3: Double percentage
[Application.ExpandMacros("%%VMPROCESSES%%")]

This complains about the brackets, although my understanding is that only macros are expanded, not functions. For macros and functions, there is ExpandMacrosAndScript().


Approach 4: use vbld_AllMacros()
[vbld_AllMacros()("VMPROCESSES").Value]

This also complains about brackets.


Funny: Message box is ok
[msgbox (vbld_AllMacros()("VMPROCESSES").Value)]



Approach 5: doubling the brackets once
[Replace(Replace((vbld_AllMacros()("VMPROCESSES").Value), "[[", "[[[["), "]]", "]]]]")]

This does not work.


Funny: with a message box, it works, but replacement is not done.
[msgbox (Replace(Replace((vbld_AllMacros()("VMPROCESSES").Value), "[[", "[[[["), "]]", "]]]]"))]


I attached my build script.
Steps 1, 2, 3, 4, 6 fail.
Steps 5, 7, 8 with message boxes are successful (but replacements are not made).

wellilein
07-13-2010, 08:04 AM
I am using Visual Build 7.5b.

kinook
07-13-2010, 05:13 PM
If the program's output contained

[System Process]

the output macro (i.e., LASTSTEP_OUTPUT) should contain the text with the brackets double (escaped) like

[[System Process]]

See the attached sample.

wellilein
07-19-2010, 07:48 AM
Thank you. As I am saving the process list in a macro, I now use the Set Macro build step and I assign the value

[Replace(Replace(vbld_AllMacros()("LASTSTEP_OUTPUT").Value,"[[","[[[["), "]]", "]]]]")]

This helps me bypassing the volatile %LASTSTEP_OUPUT% macro.

kinook
07-19-2010, 07:56 AM
You could also use vbld_EscapeString when assigning your macro value.
http://www.kinook.com/VisBuildPro/Manual/sysscriptmisc.htm