Skip to content

Commit

Permalink
Make sure the binary is the system PowerShell 5.1
Browse files Browse the repository at this point in the history
Sometimes a different version of the PowerShell binary `powershell.exe`
may take precedence in environment variable `Path` and may cause the
script to fail.
  • Loading branch information
thanhph111 committed Oct 1, 2021
1 parent 00f2249 commit 3809c22
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions imagepaste/clipboard/windows/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,17 @@ def get_powershell_args(script: str) -> list[str]:
Returns:
list[str]: A list of PowerShell arguments for operating a process.
"""
POWERSHELL = [
"powershell",
from os import getenv
from os.path import join

powershell_args = [
join(
getenv("SystemRoot"),
"System32",
"WindowsPowerShell",
"v1.0",
"powershell.exe",
),
"-NoProfile",
"-NoLogo",
"-NonInteractive",
Expand All @@ -106,5 +115,5 @@ def get_powershell_args(script: str) -> list[str]:
"[System.Text.Encoding]::UTF8\n"
"$PSDefaultParameterValues['*:Encoding'] = 'utf8'\n" + script
)
args = POWERSHELL + ["& { " + script + " }"]
args = powershell_args + ["& { " + script + " }"]
return args

0 comments on commit 3809c22

Please sign in to comment.