Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python中的命令从同一目录执行cmd_Python_Python 2.7_Cmd - Fatal编程技术网

使用python中的命令从同一目录执行cmd

使用python中的命令从同一目录执行cmd,python,python-2.7,cmd,Python,Python 2.7,Cmd,我有一个名为Scripts的文件夹,其中有文件。即test.py和ffmpeg.exe 现在,我想在test.py中编写一个代码,使用一些参数/命令在同一目录中执行这个ffmpeg.exe 我查找了它,但只找到了如何使用参数执行cmd。我不想调用cmd,然后更改目录并执行此命令 还有其他方法吗?子流程。Popen有一个cwd选项来指定工作目录 import os import subprocess # Absolute path to directory of where this scrip

我有一个名为Scripts的文件夹,其中有文件。即test.py和ffmpeg.exe 现在,我想在test.py中编写一个代码,使用一些参数/命令在同一目录中执行这个ffmpeg.exe

我查找了它,但只找到了如何使用参数执行cmd。我不想调用cmd,然后更改目录并执行此命令


还有其他方法吗?

子流程。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)

好吧,我对代码所做的就是先得到目录,然后按照casualdemon的要求去做。这最终奏效了:)


由于某种原因,它不起作用。我可能做错了什么。但是,我得到了类似的工作。
working_directory = os.getcwd()
p = subprocess.Popen(['my command here'], cwd=working_directory)
p.wait()