subprocess.Popen([“open”,“target.mkv”],shell=True打开指定fi失败

2024-06-30 16:46:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在学习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”选项更可取

[]选项打开文件失败有什么问题


Tags: 文件oftheinenglishdownloads选项open
1条回答
网友
1楼 · 发布于 2024-06-30 16:46:43

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.

相关问题 更多 >