【问题标题】:Python suprocess.run() for Windows [duplicate]适用于 Windows 的 Python subprocess.run() [重复]
【发布时间】:2020-12-02 08:44:00
【问题描述】:

我创建了一个 png 文件并在 macOS 上使用

[...]
image.save("mandel.png", "PNG")
p = subprocess.run(["open", "mandel.png"], capture_output=True)
print(p.stdout.decode(),p.stderr.decode())

但是我要为 Windows 选择什么? "open" 在 Win10 上不起作用。

【问题讨论】:

    标签: python subprocess


    【解决方案1】:
    [...]
    image.save("mandel.png", "PNG")
    p = subprocess.run(["start", "mandel.png"], capture_output=True)
    print(p.stdout.decode(),p.stderr.decode())
    

    您可以在 windows 中使用start 命令。

    参考:

    http://www.frankworsley.com/blog/2007/9/24/open-a-file-in-the-default-application-using-the-windows-command-line-without-jdic

    【讨论】:

    • 不适用于 Win10(在 macOS 的虚拟框中)。我不得不使用os.startfile("mandel.png", 'open')
    猜你喜欢
    • 1970-01-01
    • 2012-02-20
    • 2020-12-20
    • 2011-12-15
    • 2021-09-25
    • 2020-05-24
    • 1970-01-01
    • 1970-01-01
    • 2013-04-10
    相关资源
    最近更新 更多