Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue: gsudo character limit - The command line is too long #364

Open
ReversePolishLogic opened this issue Jul 2, 2024 · 1 comment
Open

Comments

@ReversePolishLogic
Copy link

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.

@gerardog
Copy link
Owner

gerardog commented Jul 4, 2024

The gsudo { script } syntax has that limitation. Interestingly, the Invoke-Gsudo function works correctly.

  1. 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 for Get-Credentials).
    • Better forwarding of your current context to the elevated instance (current Location, $ErrorActionPreference)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants