win-sudo icon indicating copy to clipboard operation
win-sudo copied to clipboard

Command doesn't execute

Open filips123 opened this issue 6 years ago • 4 comments

When I try to execute a command with sudo, it doesn't execute. It shows UAC prompt but the command is never executed.

filips123 avatar May 13 '19 19:05 filips123

Same for me. Although I do not get UAC prompt.

niels-bosman avatar Mar 11 '20 10:03 niels-bosman

I was having the same issue. I've not fixed it, but when I change the line with the PowerShell command to

if ! powershell.exe "Start-Process \"$(cygpath -w /bin/)bash\" \"$backend\", \"$fifoid\" -Verb RunAs -WorkingDirectory \"\$PWD\" -Wait; (\$Error[0]).InvocationInfo.Line"; then

the Bash window that appears complains that /dev/cons1: No such device or address when running the $SHELL -c "$command_to_run" >"$stdout" 2>"$stderr" <"$stdin" & line of sudobackend.

Hopefully this is useful information rather than a new problem I've introduced with my meddling.

chrisdjali-wrld3d avatar Nov 04 '20 13:11 chrisdjali-wrld3d

I think what's going on here is that the author was expecting -WindowStyle Hidden to work like -NoNewWindow where the process is spawned in the current console session, so then when the sudo script gets the filenames for its input and output, if it was connected up to the Cygwin pseudo device for the current console (e.g. /dev/cons1) the same device would be available from the sudobackend script. However, the backend script gets a fresh console, and can only see /dev/cons2 due to what Cygwin's Special Filenames docs describe as a restriction in Windows.

The solution would be to switch from -WindowStyle Hidden to -NoNewWindow, but that's not part of the same parameter set as -Verb, so can't be used at the same time, and -Verb RunAs is where all the magic happens.

As for why this works for some people and not others, I think there's a difference between the MinTTY console Git Bash uses by default and other Windows consoles. If the console is MinTTY (e.g. Git Bash has been started directly) sudo works just fine and the stdin, stdout, and stderr sudobackend uses are all /dev/pty0 (potentially with a different number). If the console is the Windows Command Host or VS Code's terminal is used, though, it doesn't work and they're all /dev/cons0 (potentially with a different number). Maybe some special handling can be added so when the outer sudo is connected to a /dev/consX it sets up a different file the sudobackend script can talk to and copies input and output to it itself.

chrisdjali-wrld3d avatar Nov 04 '20 14:11 chrisdjali-wrld3d

install node js

raymondmgeni avatar Feb 09 '22 20:02 raymondmgeni

Fixed in 5b2d65b4d38ee612598fa94980dacfa6e64b79c7 ?

riedel avatar Mar 04 '23 20:03 riedel

Seems to be, although the Windows install I was initially hitting this issue on no longer exists, so I'm not testing it under exactly the same conditions as when I originally hit the problem.

chrisdjali-wrld3d avatar Mar 06 '23 11:03 chrisdjali-wrld3d

Guess we won't really be able to check this in any other way, then. Feel free to open another issue if this still happens

purplesyringa avatar Mar 06 '23 21:03 purplesyringa