Giter Site home page Giter Site logo

Comments (5)

gerardog avatar gerardog commented on June 10, 2024 1

The parameter binding on native calls from PowerShell have some special rules, like: if a scriptblock appears, use a special powershell to powershell parameter binding, which encodes the scriptblock... and also the -noninteractive is added by powershell itself, when it thinks it's invoked from a non-interactive host.
I can understand the 'integrated terminal' would trigger this issue, since clearly is a non-interactive host, but I still don't understand why do you get that effect in the regular terminal as you shown 👇
image

Do you still get the error in the interactive terminal ? can you try pwsh -noprofile then gsudo to see if that makes a difference?

Here is a potential fix for the issue: https://github.com/gerardog/gsudo/releases/tag/v2.4.1-fixnoninteractive

from gsudo.

gerardog avatar gerardog commented on June 10, 2024

Hi @fmotion1!

One thought I had is that gsudo.exe and gsudo are in a separate folder (in my PATH) than the actual module files. Could this cause trouble?

Rarely, I guess.. You are calling gsudo, so please run Get-Command gsudo and verify it is returning either gsudo.exe or gsudo function from gsudoModule. If the first or only results is the C:\Program Files\gsudo\Current\gsudo (no extension) bash script, then we may have a problem there.

If that were the problem, calling gsudo.exe instead of gsudo might fix the error, or doing a regular install. Anyway, If this was the case, I wouldn't expect this error message.

  • I am not able to trigger that -NonInteractive argument, so help me identify why your code is running non-interactively. How are you invoking the.ps1 file? What pwsh.exe or pwsh console host are you using? Specific Pwsh verision? Does Pwsh any experimental feature enabled?
    For example, if this script is invoked from, let's say, scoop, that may help me reproduce the problem.

Could you please do gsudo --debug { command } and paste the output? let's see where the -NonInteractive is placed.

Unrelated: the $args[0] needs a fix. You can pass an argument with $args[0], but if you prepend it with 'defaultcurhoplimit=' then pwsh will treat it as a double quoted string and treat [0] as a string literal

image

from gsudo.

fmotion1 avatar fmotion1 commented on June 10, 2024

gsudo binaries are in C:\BIN\gsudo which is in my PATH.

I'm invoking the script from within VSCode as well as in the Pwsh7 console. Errors remain the same.

PowerShell Version: 7.3.7
 PSEdition: Core

I am not able to trigger that -NonInteractive argument, so help me identify why your code is running non-interactively.

It shouldn't (isn't) running non-interactively at all. The script prompts the user several times for input and depends on that input to function. I don't have a -noninteractive flag set anywhere.

This is interesting though:

Code_JdfLFTVsZP

Even without any code in the scriptblock it's still erroring out:

Debug: Command Line: -noninteractive --debug -encodedCommand IAA= -inputFormat xml -outputFormat xml
Error: Invalid option: o in -noninteractive

If I run my script, I get the following:

Code_VkgJL63CXJ

Debug: Command Line: -noninteractive --debug -encodedCommand IABuAGUAdABzAGgAIABpAG4AdAAgAGkAcAB2ADQAIABzAGUAdAAgAGcAbABvAGIAIABkAGUAZgBhAHUAbAB0AGMAdQByAGgAbwBwAGwAaQBtAGkAdAA9ACQAKAAkAGEAcgBnAHMAWwAwAF0AKQAgAD4ATgBVAEwAIAA= -inputFormat xml -outputFormat xml
Error: Invalid option: o in -noninteractive
Debug: Command Line: -noninteractive --debug -encodedCommand IABuAGUAdABzAGgAIABpAG4AdAAgAGkAcAB2ADYAIABzAGUAdAAgAGcAbABvAGIAIABkAGUAZgBhAHUAbAB0AGMAdQByAGgAbwBwAGwAaQBtAGkAdAA9ACQAKAAkAGEAcgBnAHMAWwAwAF0AKQAgAD4ATgBVAEwAIAA= -inputFormat xml -outputFormat xml
Error: Invalid option: o in -noninteractive
Debug: Command Line: -noninteractive --debug -encodedCommand IAByAGUAZwAgAGEAZABkACAAIgBIAEsARQBZAF8ATABPAEMAQQBMAF8ATQBBAEMASABJAE4ARQBcAFMAWQBTAFQARQBNAFwAQwB1AHIAcgBlAG4AdABDAG8AbgB0AHIAbwBsAFMAZQB0AFwAUwBlAHIAdgBpAGMAZQBzAFwAVABjAHAAaQBwADYAXABQAGEAcgBhAG0AZQB0AGUAcgBzACIAIAAvAHYAIABEAGkAcwBhAGIAbABlAGQAQwBvAG0AcABvAG4AZQBuAHQAcwAgAC8AdAAgAFIARQBHAF8ARABXAE8AUgBEACAALwBkACAAMwAyACAALwBmACAA -inputFormat xml -outputFormat xml
Error: Invalid option: o in -noninteractive

If this helps, here's the code:

Clear-Host

$PingResult = & ping 127.0.0.1
$PingResult[2] -match 'TTL=([\d]+)'
$CurrentTTL = $Matches[1]

Invoke-SpectrePrintMarkup -Message "--------------------------------------------------------`n"
Invoke-SpectrePrintMarkup -Message "[grey66]Current TTL Value is[/] [white]$CurrentTTL[/]`n"
Invoke-SpectrePrintMarkup -Message "--------------------------------------------------------`n"

Invoke-SpectrePrintMarkup -Message "[grey66]Windows 10 Default value for DefaultTTL is[/] [white]128[/]"
Invoke-SpectrePrintMarkup -Message "[grey66]Reccommended tweaked values are in the range of [/][white]55-70[/]`n"
[System.String]$TTLSelection = Invoke-SpectreTextPrompt -Prompt "[#00d787]Specify your desired DefaultTTL:[/]"

$TTLSelectionInt = $TTLSelection -as [int]
while(($TTLSelectionInt -lt 55) -or ($TTLSelectionInt -gt 128)){
    Write-Error "TTL Value is outside of the reccommended range. Please enter a different value.`n"
    [System.String]$TTLSelection = Invoke-SpectreTextPrompt -Prompt "[#00d787]Specify your desired DefaultTTL:[/]"
    $TTLSelectionInt = $TTLSelection -as [int]
}

if($TTLSelectionInt -eq 128){
    $Prompt = "Are you sure you want to reset [WHITE]DefaultTTL[/] to default? ($TTLSelectionInt)"
    $Success = "`nSetting [white]DefaultTTL[/] to [white]$TTLSelectionInt[/] now.`n"
    $Result = Invoke-SpectreTextPromptConfirm -Prompt $Prompt -ConfirmSuccess $Success
    if($Result -ne "Y"){
        exit
    }


    gsudo --debug { netsh int ipv4 set glob defaultcurhoplimit=128 >NUL }
    gsudo --debug { netsh int ipv6 set glob defaultcurhoplimit=128 >NUL }
    gsudo --debug { reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters" /v DisabledComponents /f }

} else {

    $Prompt = "Are you sure you want to set [WHITE]DefaultTTL[/] to $TTLSelectionInt`?"
    $Success = "`nSetting [WHITE]DefaultTTL[/] to [white]$TTLSelectionInt[/] now.`n"
    $Result = Invoke-SpectreTextPromptConfirm -Prompt $Prompt -ConfirmSuccess $Success
    if($Result -ne "Y"){
        exit
    }

    gsudo --debug { netsh int ipv4 set glob defaultcurhoplimit=$($args[0]) >NUL } -args $TTLSelectionInt
    gsudo --debug { netsh int ipv6 set glob defaultcurhoplimit=$($args[0]) >NUL } -args $TTLSelectionInt
    gsudo --debug { reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters" /v DisabledComponents /t REG_DWORD /d 32 /f }

}

Invoke-SpectrePrintMarkup -Message "`n[white]DefaultTTL[/] has been set to [white]$TTLSelectionInt[/]`n"
read-host "You may close this window now or press any key to exit."

Even if I just do this: gsudo --debug { Get-Process }, I still get:

Debug: Command Line: -noninteractive --debug -encodedCommand IABHAGUAdAAtAFAAcgBvAGMAZQBzAHMAIAAgAA== -inputFormat xml -outputFormat xml
Error: Invalid option: o in -noninteractive

I have no idea what's going on. In the meantime, I've switched to another elevation technique. Hopefully this gets sorted because I really love the idea of gsudo!

Appreciate any help. Let me know if there is any more information I can give you.

from gsudo.

fmotion1 avatar fmotion1 commented on June 10, 2024

OK! I've made some progress!

I've successfully got it to work outside VSCode if I run the script directly. Furthermore, I also replaced all gsudo references with gsudo.exe since Get-Command gsudo was pointing to the non-exe binary.

But running within VSCode still produces the error. I know positively that VSCode does Automatic script injection. So I was thinking the -noninteractive argument was originating from that injected code.

If I run code --locate-shell-integration-path pwsh it prints the injection script path:

c:\Users\futur\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\contrib\terminal\browser\media\shellIntegration.ps1

But I checked that script and there is no -noninteractive flag set anywhere in the file. So that's frustrating. But at least I've narrowed the problem down to VSCode.

Is there any way you can test/troubleshoot this on your end?

I've attached the shell integration script to this post.

shellIntegration.zip

from gsudo.

fmotion1 avatar fmotion1 commented on June 10, 2024

Just saw the commit... Awesome! I hope it makes it into release soon. Just some further info - I can actually get the script to work in VSCode if I run the script "In a new terminal" (It's a feature in the PowerShell Pro Tools VSCode extension).

Image for reference:

UduqnqBFfA

This is definitely leading me to believe that the integrated terminal is spawning with the -noninteractive flag set. I just don't know where it's coming from.

Either way, I hope the latest commit works!

from gsudo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.