Skip to content

feat:发现目前windows环境终端硬编码ps5,我已提交推送修改为优先ps7 #484

@desmonna

Description

@desmonna

code_run 在 Windows 上执行 PowerShell 脚本时,目前会硬编码 powershell (Windows PowerShell 5.1)。此 PR 将使其在可用时优先使用 pwsh(PowerShell 7+),而在未安装时则退回到传统的 powershell

PowerShell 7 现在是推荐并积极维护的版本,大多数 Windows 环境都已安装。与 5.1 相比的主要优势:

  • 更好的 UTF-8 支持
  • 消除了代码输出中的乱码中日韩字符
  • 跨平台一致性
  • 在 Windows/Linux/macOS 上具有相同的 shell 行为
  • 现代语法 - 改进了错误处理、三元运算符、管道链运算符
  • 性能 - 启动和执行速度明显加快

Changes

ga.py — 2 lines changed (net +2):

-import tempfile, traceback, subprocess, itertools, collections, difflib
+import tempfile, traceback, subprocess, itertools, collections, difflib, shutil

     elif code_type in ["powershell", "bash", "sh", "shell", "ps1", "pwsh"]:
-        if os.name == 'nt': cmd = ["powershell", "-NoProfile", "-NonInteractive", "-Command", code]
+        if os.name == 'nt':
+            _ps = "pwsh" if shutil.which("pwsh") else "powershell"
+            cmd = [_ps, "-NoProfile", "-NonInteractive", "-Command", code]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions