-
Notifications
You must be signed in to change notification settings - Fork 119
Issues on windows when the username contains &
#97
Comments
Thanks @zvin , can you please provide any sample error messages? That will help me narrow this down. |
It errors here https://github.com/jorangreef/sudo-prompt/blob/master/index.js#L589 const sp = require('sudo-prompt');
const options = { name: 'test' };
sp.exec('echo ok', options, (error, stdout, stderr) => {
console.log({ error, stdout, stderr });
}); The elevate script looks like this and fails when I run it with @echo off
call "C:\Users\KRS&KR~1\AppData\Local\Temp\9f9c5cce3172619ac463295721953625\command.bat" > "C:\Users\KRS&KR~1\AppData\Local\Temp\9f9c5cce3172619ac463295721953625\stdout" 2> "C:\Users\KRS&KR~1\AppData\Local\Temp\9f9c5cce3172619ac463295721953625\stderr"
(echo %ERRORLEVEL%) > "C:\Users\KRS&KR~1\AppData\Local\Temp\9f9c5cce3172619ac463295721953625\status" |
Thanks @zvin, I could not reproduce any error. To make sure it's not a 8.3 short name issue, I created a directory called I then created
This should be exactly the same as your example, except with a different 8.3 short name.
I then ran this with:
Everything ran smoothly, the status code returned was 0, and the stdout file contained Also, the example you posted looks like it is properly escaped. Are you sure this is not an issue with your command itself? |
I can reproduce the issue reliably. powershell.exe Start-Process -FilePath "'C:\Users\KRS&KR~1\AppData\Local\Temp\81a1d4081334e8e3ac6906e9bd180f37\execute.bat'" -WindowStyle hidden -Verb runAs Launching it by hand does not create the |
The command itself is |
I can reproduce it now. Ignoring anything specific to
Just save this as The interesting thing here is we are relying on the current working directory to pass the full path to the If the full path to these files has no ampersand, everything will work. But, if the full path includes an ampersand, Windows itself won't escape the ampersand when |
Whether we elevate using VBScript or PowerShell, the issue is actually in We are passing the path correctly here: https://github.com/jorangreef/sudo-prompt/blob/master/index.js#L523 But PowerShell is not escaping the path when it proceeds to call I don't know how we can do the escaping for PowerShell. If we try, PowerShell doesn't seem to find the file we are trying to run (I think it stats it first before calling The only way seems to be to put the Maybe you can give the escaping a shot to see if you come up with another solution? Alternatively, in your case, you might try not using the 8.3 short name, i.e. use the long path, since that will probably not have any ampersands in it. We could also try something where if we see the path is an 8.3 short name, then we find a way to expand it (any ideas?), to get rid of the ampersand. |
The ampersand is in the user name so it is also in the name of his home folder, short names only add the |
@bitcrazed could we get some advice from your team on this? The issue is that an ampersand in the username is breaking the script for both powershell and vbscript, see #97 (comment) |
@bitcrazed, the issue seems to be something internal to powershell and vbscript, since we're letting them do the escaping of the ampersand in #97 (comment), by referencing a file in the same cwd. It's only the full path to the cwd that contains the ampersand. The idea behind this was to rule out any escaping errors on our side. |
Ping @bitcrazed, I'm pretty sure this is a bug in Windows' shell escaping... If you can put anyone else at Microsoft onto this it would be much appreciated. |
Hey @jorangreef - could I ask you to file an issue in https://github.com/microsoft/terminal/ referencing this issue? We'll triage and comment there. |
Thanks @bitcrazed, done: microsoft/terminal#2419 |
…folder and running it from here
…folder and running it from here
If the username contains a
&
(likeAlice & Bob's Laptop
), sudo-prompt fails on windows.Most probably because the temporary file is in the user's folder and
&
s are not escaped.The text was updated successfully, but these errors were encountered: