【问题标题】:Remove over powershell windows 10 Apps删除 over powershell windows 10 Apps
【发布时间】:2021-03-30 03:37:45
【问题描述】:

我构建了一个脚本来删除每个 Python 的 Windows 10 应用程序。 我将要删除的应用程序保存在字符串数组中,并将完整的命令保存在变量中。

然后我运行命令,出现错误:Remove-AppxPackage 命令拼写错误或 找不到。

我编写了以下代码:

    win10Apps = ["3d", "camera"]
       for app in win10Apps:
       psCommand = "Get-AppxPackage " + app + " | Remove-AppxPackage"
       pyautogui.press("Enter")
       os.system("powershell.exe " + psCommand)
       pyautogui.press("Enter")

【问题讨论】:

  • 阅读错误信息? x 标记位置。
  • edit 修复minimal reproducible example 中的缩进问题。试试os.system('powershell.exe -c "{}"'.format( psCommand))
  • 好的,谢谢!代码现在可以工作了! @JosefZ

标签: python powershell windows-10


【解决方案1】:

正如 JosefZ 在 cmets 中提到的,在调用其他可执行文件时必须格式化参数。

固定代码如下所示:

win10Apps = ["3d", "camera"]
for app in win10Apps:
    psCommand = "Get-AppxPackage " + app + " | Remove-AppxPackage"
    pyautogui.press("Enter")
    os.system('powershell.exe -c "{}"'.format( psCommand))
    pyautogui.press("Enter")

对于特殊字符你也可以need to escape。另外,这里是Get-AppxPackageRemove-AppxPackage 的文档。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    • 2018-06-20
    • 1970-01-01
    • 2019-04-11
    • 1970-01-01
    相关资源
    最近更新 更多