Kinook Software Forum

Go Back   Kinook Software Forum > Visual Build Professional > [VBP] General Discussion
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-30-2004, 01:03 PM
lecm lecm is online now
Registered User
 
Join Date: 08-11-2004
Posts: 3
Setting an env. var. from custom action step error...

Hi!

I'm building a custom step action. Is this step, I set a macro that I want to be set as an environment variable when calling external programs. So, what I'm doing is this in the custom action :

Set objMacroColl = objAppl.Macros(VisBuildSvr.MacroTypeEnum.vbldMacro Temporary)
objMacroColl.Add MY_VARIABLE, "the value of variable", , , True

Every thing is good except that when I call an external program, the program doesn't see the variable I set!

PS : I tried setting a variable from a "SetMacro" action and checked the "add to env. var. ..." and it worked!

Please, tell what's wrong!
Reply With Quote
  #2  
Old 09-30-2004, 01:35 PM
kevina kevina is online now
Registered User
 
Join Date: 03-27-2003
Posts: 825
Without seeing how the code you are using I can only speculate, but this script step example demonstrates something similar, in vb script it creates a macro (and makes it available as an environment variable) then invokes cmd.exe. If I type SET in that instance of cmd.exe, the macro is listed as an environment variable.

If this doesn't help, please provide more detai on how you are invoking this external application.

<step action='Run Script' type='0'>
<Language>VBScript</Language>
<Script><![CDATA[Set objMacroColl = Application.Macros(vbldMacroTemporary)
objMacroColl.Add "ENV_MACRO", "ENV_MACRO value", , , True

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "cmd.exe"]]></Script>
<indent type='3'>1</indent>
<name>Test script step</name>
</step>

Note: just copy/paste the above xml fragment into Visual Build Pro for a step that you can review/use.
Reply With Quote
  #3  
Old 09-30-2004, 01:43 PM
lecm lecm is online now
Registered User
 
Join Date: 08-11-2004
Posts: 3
Something is still wrong...

Hi! Thx for your quick answer.

I took your code step and created a file named "MyTest.bld". Opened VisBuildPro. Executed the step, a console window opened. I typed "set" and I don't see your "ENV_MACRO" in my variables!

I installed the 5.5 version. Are you using the same version as I am?

Thx again!
Reply With Quote
  #4  
Old 09-30-2004, 02:08 PM
kevina kevina is online now
Registered User
 
Join Date: 03-27-2003
Posts: 825
You are correct (I should have known better, somehow my quick test looked like it worked but didn't).

The help contents do cover this (that you have to restart the build after adding a macro via script to be added to the environment variables), but also mention the advanced.bld sample as describing a workaround (dynamically creating a bld to add the macro(s), and running it first).

Here is an adaptation of that sample demonstrating a working workaround <grin>.

' this method creates a new project, does not save it, and builds
' the temporary in-memory project without showing a GUI

' the generated project has two Set Macro steps marked to update
' environment variables, to work around the fact that environment
' variables are not updated immediately from script code; they
' are from a Set Macro action run in the same process

Option Explicit

Dim objApp, objBld, objStep, objMacro

' create VisBuildPro app and build objects and connect
Set objBld = CreateObject("VisBuildSvr.Builder")
Set objApp = CreateObject("VisBuildSvr.Application")
objBld.Initialize objApp

' create an empty LOGFILE macro to disable logging of the
' temporary project
Set objMacro = objApp.Project.Macros.Add("LOGFILE", "")

' create a couple macros updating environment variables
' calls project script function AddSetMacroStep
AddSetMacroStep objApp.Project, "ENV_Macro", "ENV_MACRO Value"

' build the generated project
objBld.SyncBuild

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "cmd.exe"

' add a Set Macro step to the project to create the
' given macro, marking to update environment variables
Sub AddSetMacroStep(objProj, macroName, macroValue)

Dim objStep, objMacro

' add a Set Macro step and set its properties
Set objStep = objApp.Project.Steps(vbldStepMain).Add("Set Macro")
objStep.Name = "Create Macro"
objStep.Indent = 0
objStep.Property("MacroType") = vbldMacroTemporary
objStep.Property("MacroName") = macroName
objStep.Property("MacroValue") = macroValue
objStep.Property("MacroEnvVar") = True

End Sub
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



All times are GMT -5. The time now is 06:45 PM.


Copyright © 1999-2023 Kinook Software, Inc.