gpt4 book ai didi

python - subprocess.Popen( ["open", "target.mkv"],shell=True 打开指定文件失败

转载 作者:太空宇宙 更新时间:2023-11-04 04:34:17 25 4
gpt4 key购买 nike

我正在学习 subprocess 打开多媒体“.mkv”文件,

首先,我测试:

In [25]: subprocess.Popen(
...: ["open", "/Volumes/Transcend/Downloads/The.Adventure.of.English.Ep4.mkv"], shell=True)
...:
Out[25]: <subprocess.Popen at 0x10b063908>
In [26]: Usage: open [-e] [-t] [-f] [-W] [-R] [-n] [-g] [-h] [-s <partial SDK name>][-b <bundle identifier>] [-a <application>] [filenames] [--args arguments]

所发生的只是提示使用信息。

然后,我尝试了:

In [27]: subprocess.Popen('open "/Volumes/Transcend/Downloads/The.Adventure.of.English.Ep4.mkv"', shell=True)
Out[27]: <subprocess.Popen at 0x10b114208>

它成功了,并立即打开了目标文件,

我注意到 [] 的第一个选项比后面的“string”选项更可取。

[] 选项无法打开文件有什么问题?

最佳答案

来自 subprocess.Popen 构造函数 ( Docs ):

The shell argument (which defaults to False) specifies whether to use the shell as the program to execute. If shell is True, it is recommended to pass args as a string rather than as a sequence.

关于python - subprocess.Popen( ["open", "target.mkv"],shell=True 打开指定文件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52089128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com