Support Forums

PrimalScript 2015 Parameters in PS V2 packager

Support for all customers who have purchased a PrimalScript product license. This forum 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.
User avatar
clum09
Posts: 114
Joined: Thu Apr 24, 2008 9:11 am

PrimalScript 2015 Parameters in PS V2 packager

Postby clum09 » Mon Jan 25, 2016 8:11 am

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: 5866
Joined: Tue May 29, 2007 4:43 pm

Re: PrimalScript 2015 Parameters in PS V2 packager

Postby Alexander Riedel » Mon Jan 25, 2016 9:28 am

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: 4459
Joined: Thu Aug 18, 2011 4:56 am

Re: PrimalScript 2015 Parameters in PS V2 packager

Postby davidc » Mon Jan 25, 2016 3:00 pm

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: 114
Joined: Thu Apr 24, 2008 9:11 am

Re: PrimalScript 2015 Parameters in PS V2 packager

Postby clum09 » Mon Jan 25, 2016 4:59 pm

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: 4459
Joined: Thu Aug 18, 2011 4:56 am

Re: PrimalScript 2015 Parameters in PS V2 packager

Postby davidc » Tue Jan 26, 2016 4:53 pm

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:

if ($EngineArgs) {
#use $EngineArgs variable we are a packaged exe
}
else {
#use $Args
}


David
David
SAPIEN Technologies, Inc.
User avatar
clum09
Posts: 114
Joined: Thu Apr 24, 2008 9:11 am

Re: PrimalScript 2015 Parameters in PS V2 packager

Postby clum09 » Wed Jan 27, 2016 7:20 am

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: 114
Joined: Thu Apr 24, 2008 9:11 am

Re: PrimalScript 2015 Parameters in PS V2 packager

Postby clum09 » Wed Jan 27, 2016 7:36 am

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.
User avatar
DevinL
Site Admin
Posts: 738
Joined: Mon Aug 17, 2015 2:25 pm

Re: PrimalScript 2015 Parameters in PS V2 packager

Postby DevinL » Wed Jan 27, 2016 12:27 pm

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 3936 times
DevinL
SAPIEN Technologies, Inc.

Return to “PrimalScript”

Who is online

Users browsing this forum: No registered users and 6 guests