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