Executable with Switches

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
rocky.pabillore
Posts: 13
Joined: Thu Aug 25, 2016 7:05 am

Executable with Switches

Post by rocky.pabillore » Mon Aug 27, 2018 10:39 am

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: PoSh Studio 2018, 5.5.154.0
32 or 64 bit version of product: 64bit
Operating system: win 10 1803
32 or 64 bit OS: 64bit

*** Please add details and screenshots as needed below. ***
So, my question is that I'm trying to create an executable with switches, and with just the \test.ps1 -hello it out puts what I need, but when it is packaged, it does not output anything.




DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

User avatar
mxtrinidad
Site Admin
Posts: 314
Joined: Sun Mar 03, 2013 12:42 pm

Re: Executable with Switches

Post by mxtrinidad » Mon Aug 27, 2018 11:03 am

I'm assuming you got the executable create "Test.exe" and that you got an argument (parameter) created to pass the value.
Again, we don't have much information from you on how the script look like.

So, I can guess the mistake is using the dash '-'. The executable is not a DOS-type command but a .NET PowerShell executable.
Remove the dash and just type the value:

Below is a code I created as an executable:

Code: Select all

<#	
	.NOTES
	===========================================================================
	 Created with: 	SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.155
	 Created on:   	8/27/2018 1:49 PM
	 Created by:   	Maximo Trinidad
	 Organization: 	SAPIEN Technologies, Inc.
	 Filename:    Testoutput.ps1 	
	===========================================================================
	.DESCRIPTION
		Sample to create an executable to passing a value.
#>

param ([string] $arg1)
	Write-Host "$arg1"

Below is the results:

Code: Select all

PS [21] > pwd

Path
----
C:\Users\max_t\Documents\SAPIEN\PowerShell Studio\Files\Testexecarg1\bin\x64


PS [28] > .\Testoutput.exe Hello
Hello
PS [30] > .\Testoutput.exe -Hello
## -> Displays nothing!
PS [32] >
I hope this help!

User avatar
rocky.pabillore
Posts: 13
Joined: Thu Aug 25, 2016 7:05 am

Re: Executable with Switches

Post by rocky.pabillore » Tue Aug 28, 2018 8:23 am

Param (
[switch]$hello,
[switch]$no

)


if ($hello)
{
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Answer is: is present", 0, "Done", 0x1)
}

elseif ($no)
{
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Answer is: hello not present", 0, "Done", 0x1)
}
else
{

$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Answer is: hello not called", 0, "Done", 0x1)

} I then compile that as a V5 Host (Command Line).. Sorry i forgot to add the source code.

User avatar
mxtrinidad
Site Admin
Posts: 314
Joined: Sun Mar 03, 2013 12:42 pm

Re: Executable with Switches

Post by mxtrinidad » Tue Aug 28, 2018 9:21 am

To be clear, switches are not automatically build in PowerShell executable. You can only pass argument(s) to the existing parameter(s) without the dash.

So, it's possible only if you add more code, which add complexity, in order to expose switches. Even when using Visual Studio then with languages like C# or VB more code still is required.

Now, to keep in simple, just add dash to the argument value, and have the PowerShell code logic handle it.
I think this should be the simplest way.

In the case you may want to display a help for the command, more code will still be needed.

:)

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

Re: Executable with Switches

Post by davidc » Tue Sep 04, 2018 7:41 am

Please refer to the following article on how to handle parameters in an package executable:

https://info.sapien.com/index.php/packa ... table-file
David
SAPIEN Technologies, Inc.