python - 删除 over powershell windows 10 Apps
问题描述
我构建了一个脚本来删除每个 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")
解决方案
正如 JosefZ 在评论中提到的那样,您必须在调用其他可执行文件时格式化您的参数。
固定代码如下所示:
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")
同样对于特殊字符,您需要转义。此外,这里是Get-AppxPackage和Remove-AppxPackage的文档。
推荐阅读
- python - Selenium webdriver 在没有会话的情况下关闭
- php - 我们如何在 PHP 中动态更改使用 GD 库创建的 png 图像的宽度和高度?
- java - Java 时钟项目 - Tick 方法在分钟和秒内输出“0”而不是“00”,修复 AM PM 的输出
- xcode - 如何摆脱 UIStackView 添加的不需要的约束?
- c# - UWP - 一次从许多不同的任务写入文件
- java - 计算归一化设备坐标
- javascript - 从 JSON 中获取唯一值
- html - 具有动态大小的列表
- java - 为什么是 Arraylist<>. sublist() 没有映射到用户定义的数据类型 arraylist<>?
- c# - 为什么我会收到“System.ArgumentOutOfRangeException”?