PrimalScript 2015 Parameters in PS V2 packager

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 LICENSE NUMBERS, ACTIVATION 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.
This topic is 8 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
clum09
Posts: 150
Last visit: Sun Jan 21, 2024 5:07 pm

PrimalScript 2015 Parameters in PS V2 packager

Post by clum09 »

Product, version and build: 7.1.74.122315
32 or 64 bit version of product: 64-Bit
Operating system: Windows 7 Professional
32 or 64 bit OS: 64-Bit

I am wondering why PrimalScript 2015 implemented the $EngineArgs variable in the PowerShell Packager. There is no need for $EngineArgs in the packaged script since the native $Args variable built into PowerShell which does exactly the same thing as $EngineArgs.

Since PrimalScript 2015 introduced the $EngineArgs variable in the packaged script, the standard $Args variable no longerworks properly when the script is packaged using SAPIEN PowerShell V2 Host (Command line) x64 engine type. The $Args variable used to output -f as the parameter now becomes f without the dash (-) in front of the f like it used to be. Before the introduction of $EngineArgs, my packaged scripts with SAPIEN PowerShell V2 Host (Command line) x64 engine type worked fine, but now these packaged scripts no longer work properly.

Please remove the $EngineArgs variable from the script packager since there is no for such a variable since the native $Args built into PowerShell does exactly the same thing as the $EngineArgs variable.

Thank you.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: PrimalScript 2015 Parameters in PS V2 packager

Post by Alexander Riedel »

It was added upon a user request. I do not remember the exact details at the moment. We are investigating this side effect.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: PrimalScript 2015 Parameters in PS V2 packager

Post by davidc »

The $Args variable is create by PowerShell and may vary depending on where the variable is called. This is one of the reasons we create an $EngineArgs variable so you can always access the original arguments.

We also updated the engines so that it automatically converts command line arguments to parameters. The PowerShell engine in turn uses these parameters to create the $Args variable. This is why the contents of $Args is slightly different than before.
For most users, this built-in parsing feature eliminates the need to manually parse the $Args variable, but if you still wish to parse the command line arguments, use the $EngineArgs variable instead.

For more details on how to use built-in parameter support, please refer the following article:

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

David
David
SAPIEN Technologies, Inc.
User avatar
clum09
Posts: 150
Last visit: Sun Jan 21, 2024 5:07 pm

Re: PrimalScript 2015 Parameters in PS V2 packager

Post by clum09 »

David,

Use PrimalScript 2015 version 7.1.72 or above to package the code below using SAPIEN PowerShell V2 Host (Command line) x64 engine type.

$args

Then launch the packaged script with these parameters: -f C:\temp -n Filename.txt. You will get an array of parameters and their values as below:

f
C:\temp
n
Filename.txt

Then package the same code using SAPIEN PowerShell V3 Host (Command line) x64 engine type and launch the packaged script with the same parameters as above. You will get the array of the parameters as shown below which is what we would have expected:

-f
C:\temp
-n
Filename.txt

However, If you package the same code using PrimalScript 2015 version 7.1.71 or lower, the output from the packaged script with either SAPIEN PowerShell V3 Host (Command line) x64 or SAPIEN PowerShell V2 Host (Command line) x64 engine type from launching the packaged script is:

-f
C:\temp
-n
Filename.txt

which is what we would have expected.

As I mentioned in my original post, the introduction of the $EngineArgs variable in the packaged script stripped out the dash character (-) from the parameter names of the $Args variable when packaged with SAPIEN PowerShell V2 Host (Command line) x64 engine type, but left the parameters intact when packaged with SAPIEN PowerShell V3 Host (Command line) x64 engine type.

Because this problem, I requested that the $EngineArgs variable be removed from the editor so my scripts, which used the $Args variable to accept the parameter inputs, will still work with SAPIEN PowerShell V2 Host (Command line) x64 engine type.

I cannot any benefit with using the $EngineArgs since the output from this variable is identical to that of the native PowerShell $Args variable - that is, the output is just an array of strings as those generated by the $Args.

Can you tell the benefits of using the $EngineArgs variable over the $Args variable? I think it just makes things more confusing when someone added something to the PowerShell script engine which the native PowerShell engine already had to begin with.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: PrimalScript 2015 Parameters in PS V2 packager

Post by davidc »

Args is populated by the PowerShell Engine and not us. This looks like a PowerShell V2 bug because it works in V3 and above. Again, this is likely because PowerShell is creating the Args variable based upon the parsed parameters that are passed to the engine.

Note: This has nothing to do with the existence of the EngineArgs variable.

I recommend adding the following check to ensure the script is compatible:
  1. if ($EngineArgs) {
  2.     #use $EngineArgs variable we are a packaged exe
  3. }
  4. else {
  5.     #use $Args 
  6. }
David
David
SAPIEN Technologies, Inc.
User avatar
clum09
Posts: 150
Last visit: Sun Jan 21, 2024 5:07 pm

Re: PrimalScript 2015 Parameters in PS V2 packager

Post by clum09 »

David,

Why it did not happen with PrimalScript 2015 version 7.1.71 and the earlier versions? PrimalScript 2015 version 7.1.71 and earlier versions did not have the $EngineArgs in the packaged script.

Before you said that "Note: This has nothing to do with the existence of the EngineArgs variable", you have to test it for yourself first. By the way, have you ever tested the packaged scripts as I suggested in the my post yet?

You have not told me the benefits of using $EngineArgs variable over the native PowerShell $Args variable, which works in either the unpackaged and packaged script prior to PrimalScript 2015 version 7.1.72 (where $EngineArgs was introduced into the editor).

I can tell the benefit of using the native PowerShell $Args variable over the $EngineArgs variable - it allows me the test my script before I package the script where using the $EngineArgs variable you have to package the script first before it exists for you to use.

Why makes things more complicated than it should be if the native PowerShell $Args variable already existed for you to use? Why not trying to fix other bugs in PrimalScript 2015 such as the PowerShell script packager crashes instead of adding the $EngineArgs variable that causes the parameters parsing problem with the native PowerShell $Args variable?
User avatar
clum09
Posts: 150
Last visit: Sun Jan 21, 2024 5:07 pm

Re: PrimalScript 2015 Parameters in PS V2 packager

Post by clum09 »

By the way, I had already used the code that you suggested to me before posted my message in this forum, but somehow the script packager keeps crashing which is another issue.

Additionally, I have a lot of scripts that I have already used the $Args variable over the last eight years. I do not want to redo any of my codes in these scripts in order to use PrimalScript 2015 version 7.1.72 and later, and this is another benefit of using the native PowerShell $Args variable instead of the $EngineArgs variable.
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: PrimalScript 2015 Parameters in PS V2 packager

Post by DevinL »

I've attempted to recreate this issue with no success so far.

I started a Windows 7 VM, installed the latest version (7.1.74), and created curr-temp.ps1 with only $args in it. Then I packaged the script to the desktop using the SAPIEN PowerShell V2 Host (Command line) x64 engine and ran it with the -f C:\temp -n Filename.txt options with the expected outcome.

After that I packaged the script using the SAPIEN PowerShell V3 Host (Command line) x64 engine, ran it with the same options, and received the same results. You can see in my screenshot the latest exe was packaged with the V3 host and I ran the exe from the command prompt.

Is there any other information regarding your setup you can provide?
PSR_Packaging_1-27.png
PSR_Packaging_1-27.png (197.91 KiB) Viewed 7477 times
DevinL
SAPIEN Technologies, Inc.
This topic is 8 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.