I've read the article at https://www.sapien.com/blog/2012/10/25/revisiting-the-packager-and-command-line-arguments/ and while I'm far from being a PS expert I reckoned it wasn't that hard to set up a test script to Write-Host each of 2 params I passed to it.
So I coped the script, added the lines:
Write-Host $Commandline
Write-Host $Commandline[0]
Write-Host $Commandline[1]
and ran the packaged script with the line
script.exe param1 param2
Clearly this wasn't right because while $commandline returns
"param1" "param2"
the next lines gave an error.
I thought it was a string that gets split up by the code above..?
Can someone tell me my obvious error, and perhaps how I should modify this to properly work with 2 params?
Many thanks,
F.
Passing parameters to exe
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- SAPIEN Support Forums
- Posts: 945
- Last visit: Thu Oct 22, 2015 1:10 pm
Passing parameters to exe
This is an automated post. A real person will respond soon.
Thank you for posting, fergusfog.
Here are some hints to help you get an accurate and complete answer to your question.
Ask in the best forum:
Anticipate follow-up questions!
Did you remember to include the following?
*** Make sure you do not post any licensing information ***
Thank you for posting, fergusfog.
Here are some hints to help you get an accurate and complete answer to your question.
Ask in the best forum:
- - Scripting question? For questions about Windows PowerShell or other scripting languages, use Scripting Answers.
- Software question? For questions about PowerShell Studio, PrimalScript, or other SAPIEN products, use Product Support Forums for Registered Customers.
- Trial question? For questions about trial versions of any SAPIEN product, use Trial Software Questions.
Anticipate follow-up questions!
Did you remember to include the following?
- 1. Product, version and build
2. 32 or 64 bit product
3. Operating system, e.g. Windows 7 64 bit.
4. Attach a screenshot, if applicable
5. Attach logs, crash reports, etc., in a ZIP file
*** Make sure you do not post any licensing information ***
Re: Passing parameters to exe
That outputs exactly the same as
Write-Host $commandline
...except in green.
Write-Host $commandline
...except in green.
- Alexander Riedel
- Posts: 8478
- Last visit: Tue Mar 26, 2024 8:52 am
- Been upvoted: 37 times
Re: Passing parameters to exe
https://www.sapien.com/blog/2010/02/09/primalforms-2009-the-packager-and-command-line-arguments/
Look at the packager commandline snippet.
Look at the packager commandline snippet.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- Alexander Riedel
- Posts: 8478
- Last visit: Tue Mar 26, 2024 8:52 am
- Been upvoted: 37 times
Re: Passing parameters to exe
James, he wasn't asking about coloring or output. He asked about handling parameters as individual strings or objects.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Passing parameters to exe
Do you mean this bit Alex..?Alexander Riedel wrote:https://www.sapien.com/blog/2010/02/09/primalforms-2009-the-packager-and-command-line-arguments/
Look at the packager commandline snippet.
Results:
$Parameter[0] = –Parameter
$Parameter[1] = Value1
$Parameter is never mentioned in the script above it, and calling these array members returns null.
As does trying to return $Arguments[0], which I would have thought is the one containing the array of args..?
How do I return param1 and param2 individually?
F.
Re: Passing parameters to exe
THe variable $CommandLine is just a string.
Processing $CommandLine creates a dictionary of name/value pairs if you have passed named parameters.
app.exe -MyParm p1 -MyParm2 p2
This gives us:
Processing $CommandLine creates a dictionary of name/value pairs if you have passed named parameters.
app.exe -MyParm p1 -MyParm2 p2
This gives us:
PowerShell Code
Double-click the code block to select all.Key Value -------- ---------- MyParam p1 MyParam2 p2There is no $Parameter array.
Re: Passing parameters to exe
You need to read this article and read it carefully:
https://www.sapien.com/blog/2010/02/09/ ... arguments/
This is how to get the dictionary:
$myparam=$named['myparam']
https://www.sapien.com/blog/2010/02/09/ ... arguments/
This is how to get the dictionary:
PowerShell Code
Double-click the code block to select all.$myargs=Parse-Commandline $CommandLine #Convert the Arguments. Use – as the Argument Indicator $named=Convert-ArgumentsToHashtable $myargs ‘-‘Now you get your arguments by name from $dictionary by name
$myparam=$named['myparam']