PS2EXE
PS2EXE copied to clipboard
PS2EXE fails to parse array arguments
When passing array arguments ps2exe does not properly handle the inputs as Powershell would.
Minimal Reproduction:
repro.ps1
param (
[string[]]$Values
)
Write-Host "Recieved $Values with a length of $($Values.Length)"
./repro.ps1 A,B,C,D,E,F
# Recieved A B C D E F with a length of 6
./repro.ps1 A, B, C, D, E, F
# Recieved A B C D E F with a length of 6
ps2exe ./repro.ps1 ./repro.exe
./reoro.exe A,B,C,D,E,F
# Recieved A,B,C,D,E,F with a length of 1
./reoro.exe A, B, C, D, E, F
# Recieved A with a length of 1
This has broken all of the existing functionality as it does not interpret the separate arguments as elements of an array.
Hello @CEbbinghaus ,
this is no issue with PS2EXE, this is a restriction of the windows environment: see the section Parameter Processing on the main page of this project: https://github.com/MScholtes/PS2EXE#parameter-processing. In your first case the first parameter is "A,B,C,D,E,F", in your second case the first parameter is "A,".
Greetings
Markus
Nice to leave a comment but isn't there a way to process the arguments based on what the powershell script requires?
Hello @CEbbinghaus;
as I have explained, an executable only gets strings from the shell. So you have to convert the string into a string array yourself, i.e. define the parameter as string
param (
[string]$Values
)
and then convert $Values.
Greetings
Markus
Or you could interate through $Args
I mean at that point I would be doing the job that powershell should be. It would be like writing my own argument parsing...
Perhaps I have expressed myself in a misleading way: PS2EXE compiles to an EXE file, and this executable then behaves like an EXE file. This is obviously not changeable.
Closed for no response for a longer time
Fair although I still believe that this functionality should be implemented. I believe that an EXE generated from a PowerShell should be (almost) indistinguishable from the original script it came from. Obviously, this has its limitations e.g passing values by reference but as far as CLI behavior is concerned the argument parsing should be identical.
The fact that this is not the case with the base PowerShell EXE baffles me to no avail and I wonder why it was so sloppily implemented.