1

I have a folder named Scripts in which I have files. Namely test.py and ffmpeg.exe Now, I want to write a code in test.py to execute this ffmpeg.exe in same directory with some arguments/commands.

I looked it up, but, only found how to execute cmd with arguments. I don't want to call cmd and then change directory and execute this command.

Any other way for this?

2 Answers 2

1

subprocess.Popen has an option of cwd to specify working directory.

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)
Sign up to request clarification or add additional context in comments.

1 Comment

For some reason it didn't work. I might've done soemthing wrong. But, I got something similar working.
0

Well,What I did with the code was get the directory first and do what casualdemon told me to do. This worked in the end :)

working_directory = os.getcwd()
p = subprocess.Popen(['my command here'], cwd=working_directory)
p.wait()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.