PV2 Packager failed to parse $args variable correctly

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
clum09
Posts: 150
Joined: Thu Apr 24, 2008 9:11 am

PV2 Packager failed to parse $args variable correctly

Post by clum09 » Mon Apr 18, 2016 9:14 am

Product, version and build: PowerShell Studio, 5.2.118
32 or 64 bit version of product: 64 bit
Operating system: Windows 7 Professional
32 or 64 bit OS: 64 bit
PowerShell Version: 2

Hello,

I have a script that accepts the parameters from the command line. When I packaged this script using the SAPIEN PowerShell V2 Host (Command line) x64 mode, the packaged script failed to output the parameters correctly. The script code is listed below with the file name of ArgTest.ps1 and is packaged into ArgTest.exe.

[Codebox]
$args
[/Codebox]

I tested the packaged script in a command prompt windows as shown in the attached picture. The top command was produced by the SAPIEN PowerShell V2 Host (Command line) x64 mode, and the bottom command was produced by SAPIEN PowerShell V3 Host (Command line) x64 mode.

As you can see, the top command removed the dash or hyphen (-) character as a part of the parameter name whereas the bottom command keeps the dash or hyphen (-) character intact. This caused all my scripts failed to work correctly.

Please let me know why this happened.

Thank you.
Attachments
ArgTest-Capture.JPG
ArgTest-Capture.JPG (23 KiB) Viewed 2340 times

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Re: PV2 Packager failed to parse $args variable correctly

Post by davidc » Mon Apr 18, 2016 9:42 am

I'm unable to reproduce this on my end. Can you provide me with the build numbers and modified dates of the following executables:

C:\Program Files\SAPIEN Technologies, Inc\PowerShell Studio 2016\ScriptEngines\SAPIEN PowerShell V2 Host (Command line) x64.exe
C:\Program Files\SAPIEN Technologies, Inc\PowerShell Studio 2016\ScriptEngines\SAPIEN PowerShell V3 Host (Command line) x64.exe

Thank you,

David
David
SAPIEN Technologies, Inc.

User avatar
clum09
Posts: 150
Joined: Thu Apr 24, 2008 9:11 am

Re: PV2 Packager failed to parse $args variable correctly

Post by clum09 » Mon Apr 18, 2016 10:59 am

David,

Attached is the versions of the two executables.
Attachments
Capture-BV.JPG
Capture-BV.JPG (80.31 KiB) Viewed 2327 times

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Re: PV2 Packager failed to parse $args variable correctly

Post by davidc » Mon Apr 18, 2016 11:49 am

Please post a screenshot of the pacakager settings as well.

1. On this machine, do you only have PowerShell V2 installed?
2. Try using the $EngineArgs variable instead and see if you get different values.

David
David
SAPIEN Technologies, Inc.

User avatar
clum09
Posts: 150
Joined: Thu Apr 24, 2008 9:11 am

Re: PV2 Packager failed to parse $args variable correctly

Post by clum09 » Mon Apr 18, 2016 12:34 pm

David,

Attached is the screen shot of packager setting for the PV2 - the one that removed the dash (-) character from the packaged script. I remembered that this happened right after SAPIEN introduced $EngineArgs variable into both Power Studio and PrimalScript.

Since SAPIEN introduced the $EngineArgs into the packager, this broke all my scripts that used the native $args variables to capture the paramters from the command line.

I will not use $EngineArgs since this variable is not the native PowerShell variable several reasons:

1. I will need to change the codes of all the scripts that I have in order to use your editor to package the scripts.
2. The $args variable will work in the packaged and unpackaged scripts, which I don't need to write the if statement to complicate matters in the my scripts, such as If ($EnginArgs) { do somthing } else { do something }.

SAPIEN already introduced the $Commandline variable in the packaged script, and then they introduced the $EnigineArgs variable which is a copy of the native $args variable. I don't care how many variables you guys introduced into the packager as long as they don't break the native variable that has been working for me the last 8 years.

Are you saying when I use your editor to write script codes, I have to use your variable? Why introduced the variable that is unnecessary and broke the native PowerShell variable?

I don't have the time to go back to all my scripts and change them because I want to use the $EngineArgs variable - there is no way!
I have too many things to than to deal with the problem that someone just wanted to produce a piece of variable into the editor - no way!!!!

Please remove this $EnginArgs so that all my scripts will work again!!!!!
Attachments
Settings.JPG
Settings.JPG (63.65 KiB) Viewed 2314 times

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Re: PV2 Packager failed to parse $args variable correctly

Post by davidc » Mon Apr 18, 2016 2:21 pm

The Args variable is created by PowerShell engine and EngineArgs is pulled directly from Windows call to the executable. There is a slight difference and one does not affect the other.

I'm not suggesting you rewrite your code. I suggested that you use the EngineArgs variable so that we can compare the two values in your sample. This will allows us to see if there was a difference from what PowerShell reported compared to what Windows reported.

You can skip parsing the Args variable altogether and use a parameter block instead with the later versions of the packager engines:

https://www.sapien.com/blog/2015/11/30/ ... able-file/

David
David
SAPIEN Technologies, Inc.

User avatar
clum09
Posts: 150
Joined: Thu Apr 24, 2008 9:11 am

Re: PV2 Packager failed to parse $args variable correctly

Post by clum09 » Tue Apr 19, 2016 5:52 am

Attached is the output from the $EngineArgs variable from SAPIEN.

Yes, SAPIEN introduced the $EngineArgs variable into the packager to break the native PowerShell $args variable in PV2. That was what I said in my previous post.

I checked the parameter block you pointed out to me. With parameter block, you have to input the parameters with quotes which is not an option for me. Also, this will require me to rewrite all my codes in order to use it.

Again, I will not rewrite all my codes to just satisfy someone who wanted to introduce a packager variable ($EngineArgs) that does exactly what the native PowerShell variable ($Args) has been doing since PowerShell was originally invented!

Please remove the $EngineArgs from the editor!!!
Attachments
EnginArgs.JPG
EnginArgs.JPG (14.97 KiB) Viewed 2188 times

User avatar
Alexander Riedel
Posts: 7055
Joined: Tue May 29, 2007 4:43 pm

Re: PV2 Packager failed to parse $args variable correctly

Post by Alexander Riedel » Tue Apr 19, 2016 11:05 am

The $engineargs variable has been added to create a common way of handling arguments that have not been modified by powershell.
Adding this variable does not break, add or remove any other functionality. It was in fact added because the powershell engine can handle arguments differently between versions. Changing code to move from one platform or version to another is simply a part of this technology.

We are not able to produce the results you see at this time. We will investigate further.
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
Alexander Riedel
Posts: 7055
Joined: Tue May 29, 2007 4:43 pm

Re: PV2 Packager failed to parse $args variable correctly

Post by Alexander Riedel » Tue Apr 19, 2016 11:36 am

I went back through the history of the code. The different handling for $args was added to accommodate those users who use script parameter blocks in their code. They requested that the way we pass arguments to the engine should be compatible with the way Powershell handles script parameters, which seems to be a reasonable request.
In order to preserve the previous handling, the $engineargs variable was added to provide a way for users to stay with their current handling by simply using a drop in replacement.
Alexander Riedel
SAPIEN Technologies, Inc.