Kinook Software Forum

Kinook Software Forum (https://www.kinook.com/Forum/index.php)
-   [VBP] General Discussion (https://www.kinook.com/Forum/forumdisplay.php?f=2)
-   -   Macro containing brackets (https://www.kinook.com/Forum/showthread.php?t=4587)

wellilein 07-13-2010 07:56 AM

Macro containing brackets
 
1 Attachment(s)
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.

Code:

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.

Code:

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.

Code:

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().

Code:

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

This also complains about brackets.

Code:

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

Code:

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

This does not work.

Code:

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 forgot the version number
 
I am using Visual Build 7.5b.

kinook 07-13-2010 05:13 PM

1 Attachment(s)
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
 
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
Code:

[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/Ma...scriptmisc.htm


All times are GMT -5. The time now is 01:55 PM.


Copyright © 1999-2023 Kinook Software, Inc.