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

Feature: Add an option to bypass shell wrapper #80

Closed
r-darwish opened this issue Feb 25, 2021 · 4 comments
Closed

Feature: Add an option to bypass shell wrapper #80

r-darwish opened this issue Feb 25, 2021 · 4 comments

Comments

@r-darwish
Copy link

Issue Description

Due to gsudo's shell detection, trying to run a command with the Windows Powershell from Powershell Core will cause gsudo to run Powershell Core first. It would be useful if we can have a flag to disable the shell detection.

Steps to Reproduce

Run the following command from Powershell core:

gsudo --debug "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.EXE" "-NoProfile" "-Command" 'echo $PSVersiontable.psversion'

Screenshots

image

Context:

  • Windows version: 20H2
  • gsudo version: 0.7.3
@gerardog
Copy link
Owner

Hi! Thanks for your really accurate bug report.

The shell detection is adding an extra 'powershell core' process, and the indirection makes it a quotation hell syntax.

Let me give you a shamefull workaround. Try:

cmd /c gsudo --debug '"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Command "Echo $PSVersionTable.PSVersion"'

or without the cmd, you need to escape the $ sign.

gsudo --debug `"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe`" -Command '"echo `$PSVersionTable.PSVersion"' 

or an example with variable substitutions:

$command='Echo $PSVersionTable.PSVersion'
gsudo --debug "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Command `"($Command.Replace("$","``$"))`"

It would be useful if we can have a flag to disable the shell detection.

I agree. It would imply that the command to run be something that can be executed by CreateProcess such as an .EXE, .CMD, .BAT or .COM. Shell statements of course won't be supported (e.g. md on cmd, CmdLets on PS).

I'm unsure on how to name the 'feature', or what letter to assign to it (as in -x). Suggestions accepted.

@r-darwish
Copy link
Author

r-darwish commented Feb 27, 2021

Hi @gerardog, thanks for the workaround. I applied it here and it seems to work. Since this is a pretty niche feature that I'm asking, I think it's okay that it will only have a full named flag, such as --no-shell

@gerardog gerardog changed the title Issue: cannot run the Windows Powershell from Powershell core Feature: Add an option to bypass shell wrapper Aug 4, 2021
@gerardog
Copy link
Owner

gerardog commented Aug 5, 2021

Hi @r-darwish, this will be released in v1.0. An early draft pre-release is open for testing in case you want to try it.
(please don't ship it into topgrade until released)

@gerardog
Copy link
Owner

gerardog commented Aug 7, 2021

Released in v1.0.0 (PR #94)

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