我有一个名为 Scripts 的文件夹,其中有文件。即test.py和ffmpeg.exe 现在,我想在 test.py 中编写一段代码,以使用一些参数/命令在同一目录中执行此 ffmpeg.exe。
我查了一下,但是只找到了如何使用参数执行 cmd。我不想调用 cmd 然后更改目录并执行此命令。
还有其他方法吗?
最佳答案
subprocess.Popen
有一个 cwd
选项来指定工作目录。
import os
import subprocess
# Absolute path to directory of where this script is located
here = os.path.abspath(os.path.dirname(__file__))
subprocess.Popen("ffmpeg.exe", cwd=here)
关于python - 使用 python 中的命令从同一目录执行 cmd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32145534/