PS2EXE icon indicating copy to clipboard operation
PS2EXE copied to clipboard

PS2EXE fails to parse array arguments

Open CEbbinghaus opened this issue 3 years ago • 4 comments

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.

CEbbinghaus avatar Oct 28 '22 06:10 CEbbinghaus

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

MScholtes avatar Oct 28 '22 08:10 MScholtes

Nice to leave a comment but isn't there a way to process the arguments based on what the powershell script requires?

CEbbinghaus avatar Oct 28 '22 08:10 CEbbinghaus

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

MScholtes avatar Oct 28 '22 16:10 MScholtes

Or you could interate through $Args

MScholtes avatar Oct 28 '22 16:10 MScholtes

I mean at that point I would be doing the job that powershell should be. It would be like writing my own argument parsing...

CEbbinghaus avatar Nov 03 '22 01:11 CEbbinghaus

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.

MScholtes avatar Nov 05 '22 08:11 MScholtes

Closed for no response for a longer time

MScholtes avatar Jan 02 '23 11:01 MScholtes

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.

CEbbinghaus avatar Jan 03 '23 12:01 CEbbinghaus