Kinook Software Forum

Go Back   Kinook Software Forum > Visual Build Professional > [VBP] Third Party Tools

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-06-2023, 03:40 PM
teognost teognost is online now
Registered User
 
Join Date: 05-25-2004
Location: Prague,Czech Republic
Posts: 200
Question Run Powershell script with parameters containing special chars

Hi
I have a Powershell step launching Test.ps1 ,in Input section I have 2 params which are 2 macros %MyParam1% and %MyParam2% (see the attach).
The problem is MyParam2 contains special chars [% so the step fails:
Error expanding macros or script in property Parameters: Test2]<Error parsing macros at position 8>
I tried as well with a batch step and it fails also:
Error expanding macros or script in property command: C:\Windows\System32\WindowsPowerShell\v1.0\powersh ell.exe -nologo -noninteractive -executionpolicy Unrestricted "& 'C:\Program Files\VisBuildPro9\Test.ps1' -Param1 'Test1' -Param2 'Test2]<Error parsing macros at position 8>'

Is there any way to launch the script Test.ps1 with second param containing special chars?
Attached Files
File Type: bld TestPowershell1.bld (1.3 KB, 3571 views)
File Type: zip Test.zip (175 Bytes, 3686 views)
Reply With Quote
  #2  
Old 03-06-2023, 07:54 PM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
[vbld_EscapeString(vbld_AllMacros()("MyParam2"))]

https://kinook.com/VisBuildPro/Manual/specialchars.htm
Reply With Quote
  #3  
Old 03-07-2023, 05:24 AM
teognost teognost is online now
Registered User
 
Join Date: 05-25-2004
Location: Prague,Czech Republic
Posts: 200
It works,thanks a lot!
Reply With Quote
  #4  
Old 03-07-2023, 06:33 PM
teognost teognost is online now
Registered User
 
Join Date: 05-25-2004
Location: Prague,Czech Republic
Posts: 200
I have one more issue,if param MyParam2 contains { I got an error at step Run Test PowerShell script-with parameters :

3/8/2023 12:26:39 AM: Building project step 2 - Run Test PowerShell script-with parameters...
C:\Windows\System32\WindowsPowerShell\v1.0\powersh ell.exe -nologo -noninteractive -executionpolicy Unrestricted "& 'C:\Program Files\VisBuildPro9\Test.ps1' Test1 Test{2[]??"
Missing closing '}' in statement block or type definition.
+ CategoryInfo : ParserError: ( : ) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndCurlyBrace

This is because the powershell script is launched with parameters without enclosing ' '

For example if I launch the script from a batch file step by adding enclosing ' ' all is ok:
3/8/2023 12:30:42 AM: Building project step 3 - Run PowerShell script from batch step...
C:\Windows\System32\WindowsPowerShell\v1.0\powersh ell.exe -nologo -noninteractive -executionpolicy Unrestricted "& 'C:\Program Files\VisBuildPro9\Test.ps1' -Param1 'Test1' -Param2 'Test{2[]??'
Param1= Test1
Param2= Test{2[]??

Is there a way to add enclosing ' ' when using a Powershell step?
I attached the bld project.
Attached Files
File Type: bld TestPowershell2.bld (1.4 KB, 3353 views)
Reply With Quote
  #5  
Old 03-08-2023, 09:00 AM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
Add the single quotes to the parameter value.
Reply With Quote
  #6  
Old 03-08-2023, 09:12 AM
teognost teognost is online now
Registered User
 
Join Date: 05-25-2004
Location: Prague,Czech Republic
Posts: 200
Tried that,same error:
C:\Windows\System32\WindowsPowerShell\v1.0\powersh ell.exe -nologo -noninteractive -executionpolicy Unrestricted "& 'C:\Program Files\VisBuildPro9\Test.ps1' Test1 ''Test{2[]??''"
Missing closing '}' in statement block or type definition.
+ CategoryInfo : ParserError: ( [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndCurlyBrace

I see now the second param has 2 chars ' at beginning and 2 at end although I added just one.
Attached Files
File Type: bld TestPowershell2.bld (2.0 KB, 3381 views)
Reply With Quote
  #7  
Old 03-09-2023, 02:33 PM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
When I run your project in v10.8, I get a command like

... -File D:\Temp\Test.ps1 Test1 'Test{2[]??'
Reply With Quote
  #8  
Old 03-09-2023, 02:40 PM
teognost teognost is online now
Registered User
 
Join Date: 05-25-2004
Location: Prague,Czech Republic
Posts: 200
I am using VBP 9.7 but I think it does not make any difference.
Did you try to copy the Test.ps1 attached in a message above to the VBP folder(%PROJDIR%)?
I get the error when running first step"Run Test PowerShell script-with parameters" which is running %PROJDIR%\Test.ps1 with 2 Input params :
%MyParam1%
'[vbld_EscapeString(vbld_AllMacros()("MyParam2"))]'

The step "Run PowerShell script from batch step" is running ok as I put there the command with Param2 enclosed with' :
C:\Windows\System32\WindowsPowerShell\v1.0\powersh ell.exe -nologo -noninteractive -executionpolicy Unrestricted "& '%PROJDIR%\Test.ps1' -Param1 '%MyParam1%' -Param2 '[vbld_EscapeString(vbld_AllMacros()("MyParam2"))]'
Reply With Quote
  #9  
Old 03-09-2023, 08:54 PM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
3/9/2023 6:53:24 PM: Building project step 2 - Run Test PowerShell script-with parameters...
C:\Program Files\PowerShell\7\pwsh.exe -nologo -noninteractive -executionpolicy Unrestricted -File D:\Temp\Test.ps1 Test1 'Test{2[]??'
Param1= Test1
Param2= 'Test{2[]??'
3/9/2023 6:53:25 PM: Build successfully completed (elapsed = 00:00:00).
Reply With Quote
  #10  
Old 03-10-2023, 05:56 AM
teognost teognost is online now
Registered User
 
Join Date: 05-25-2004
Location: Prague,Czech Republic
Posts: 200
This is strange ,do not understand why you can run it ok but when I run it I get:
3/10/2023 11:52:52 AM: Building project step 2 - Run Test PowerShell script-with parameters...
C:\Windows\System32\WindowsPowerShell\v1.0\powersh ell.exe -nologo -noninteractive -executionpolicy Unrestricted "& 'C:\Program Files\VisBuildPro9\Test.ps1' Test1 ''Test{2[]??''"
Missing closing '}' in statement block or type definition.
+ CategoryInfo : ParserError: ( [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndCurlyBrace

The second parameter in Input window is:
'[vbld_EscapeString(vbld_AllMacros()("MyParam2"))]'

Maybe I have some options activated you do not have?
Or maybe could you please try to run in in VBP 9.7 (same version as me )?
Reply With Quote
  #11  
Old 03-10-2023, 12:12 PM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
I get the same result as you in v9.7.
Reply With Quote
Reply

Tags
powershell , special charcaters

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 04:08 PM.


Copyright © 1999-2023 Kinook Software, Inc.