Issue: gsudo character limit - The command line is too long
ReversePolishLogic opened this issue · 2 comments
Issue Description
Using gsudo to elevate a command over 3,008 characters long results in a 'The command line is too long' error. (in powershell, I did not try this in any other context) From this documentation I found while researching this issue the actual character limit in practice should be much higher.
Proposed technical details
None, assuming this is a limitation just putting this out here for visibility because I could not find that anyone else encountered this before.
The gsudo { script }
syntax has that limitation. Interestingly, the Invoke-Gsudo
function works correctly.
Invoke-gsudo wrapper function: (much slower)
# Pass values (not variables by reference) by prefixing `$using:`. I.E. $MyString = "Hello World" Invoke-Gsudo { Write-Output $using:MyString } # Syntax: Invoke-Gsudo [-ScriptBlock] <ScriptBlock> [[-ArgumentList] <Object[]>] [-InputObject <PSObject>] [-LoadProfile | -NoProfile] [-Credential <PSCredential>]
- PowerShell function.
- Performs auto serialization of inputs & outputs.
- You can prefix variables with the
$using:
scope modifier (like$using:variableName
) and their serialized value is applied.- Use
-LoadProfile
or-NoProfile
to override profile loading or not.- Use
-Credential
option for Run As User (same as-u
but forGet-Credentials
).- Better forwarding of your current context to the elevated instance (current Location, $ErrorActionPreference)
Closing this issue, can confirm that the Invoke-Gsudo
function works correctly in this context.
Shortly after posting this I decided running a command the length of a short story was bad practice and re-wrote my code into a for loop. This presented another issue (using either function) where some, but not all commands in the loop consistently, randomly fail to execute with the following error: (The output seems very similar to #111)
Server Error: Setting token failed.
The operation completed successfully.
Error: Failed to substitute token. Connection from server lost.