You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was creating a python script that requires elevation, and I just decided to use gsudo to provide the elevation. I noticed that it would succeed when I ran the script directly (python ...) or with gsudo python .... But when I ran it with gsudo !! (after running it directly with python ...), it never actually ran the script.
Steps to Reproduce
Open PowerShell (with gsudoModule imported in your PowerShell profile)
Run a command that accepts a file path as the last argument, and add an extra backslash at the end of your path. (For example: ls .\FOLDER\)
Now run gsudo !! and observe that no command output is show (This is because the command was never actually run)
You can also run the command directly with gsudo (For example: gsudo "ls .\FOLDER\")
Logs
Succesfull Run
gsudo.exe --loglevel All "python .\test.py .\a"
Debug: Invoking Shell: PowerShellCore
Debug: Command Line: --loglevel All "python .\test.py .\a"
Debug: Command to run: "C:\Program Files\PowerShell\7\pwsh.EXE" -NoLogo -NoProfile -Command "python .\test.py .\a"
Debug: Using Console mode TokenSwitch
Debug: Caller PID: 22348
Debug: Connected via Named Pipe ProtectedPrefix\Administrators\gsudo_[REDACTED].
Debug: Creating target process: "C:\Program Files\PowerShell\7\pwsh.EXE" -NoLogo -NoProfile -Command "python .\test.py .\a"
Debug: Process token successfully substituted.
You should see this
['.\\test.py', '.\\a']
Debug: Process exited with code 0
Silently Failed Run
gsudo.exe --loglevel All "python .\test.py .\a\"
Debug: Invoking Shell: PowerShellCore
Debug: Command Line: --loglevel All "python .\test.py .\a\\"
Debug: Command to run: "C:\Program Files\PowerShell\7\pwsh.EXE" -NoLogo -NoProfile -Command "python .\test.py .\a\\\"
Debug: Using Console mode TokenSwitch
Debug: Caller PID: 22348
Debug: Connected via Named Pipe ProtectedPrefix\Administrators\gsudo_[REDACTED].
Debug: Creating target process: "C:\Program Files\PowerShell\7\pwsh.EXE" -NoLogo -NoProfile -Command "python .\test.py .\a\\\"
Debug: Process token successfully substituted.
Debug: Process exited with code 1
Additional Info
Trying to run the actual PowerShell Command that gsudo generates still works.
My guess is that when parsing the command, it doesn't correctly escape the ending backslash, and that is causing something to happen internally with backslashes escaping quotation marks that shouldn't be.
It seems that it correctly escapes the backslashes (.\a\ -> .\a\\) when getting the command line arguments (Debug: Command Line: --loglevel All "python .\test.py .\a\\"), but something wrong happens when it converted the command to a PowerShell Command (.\a\\ -> .\a\\\).
Issue Description
I was creating a python script that requires elevation, and I just decided to use gsudo to provide the elevation. I noticed that it would succeed when I ran the script directly (
python ...
) or withgsudo python ...
. But when I ran it withgsudo !!
(after running it directly withpython ...
), it never actually ran the script.Steps to Reproduce
gsudoModule
imported in your PowerShell profile)ls .\FOLDER\
)gsudo !!
and observe that no command output is show (This is because the command was never actually run)gsudo "ls .\FOLDER\"
)Logs
Succesfull Run
Silently Failed Run
Additional Info
Trying to run the actual PowerShell Command that gsudo generates still works.
My guess is that when parsing the command, it doesn't correctly escape the ending backslash, and that is causing something to happen internally with backslashes escaping quotation marks that shouldn't be.
It seems that it correctly escapes the backslashes (
.\a\ -> .\a\\
) when getting the command line arguments (Debug: Command Line: --loglevel All "python .\test.py .\a\\"
), but something wrong happens when it converted the command to a PowerShell Command (.\a\\ -> .\a\\\
).Context:
23H2 (OS Build: 22631.4249)
v2.5.1 (Branch.tags-v2.5.1.Sha.25d89fcac99b25534108804cb843fcbebe05a872)
The text was updated successfully, but these errors were encountered: