0

I have this python code:

        import os
        os.system('cd C:\yt')
        os.system("ffmpeg.exe -i test.mp4 newfilename.mp3")

The yt folder include the ffmeg.exe and test.mp4 but I write the code apart on cmd everthing is working but thus I get this error message:

       'ffmpeg.exe' is not recognized as an internal or external command,
       operable program or batch file.

if I use C:\yt\ffmpeg.exe -i test.mp4 newfilename.mp3 is not working and if i use only os.system('cd C:\yt') i not get error message. What's wrong with my code?

2
  • os.system executes commands in a subshell, which means that the second command is not executed in C:\yt Commented Oct 1, 2017 at 14:02
  • I reoommend: subprocess.call("ffmpeg.exe -i test.mp4 newfilename.mp3",cwd=r"c:\yt") Commented Oct 1, 2017 at 14:05

1 Answer 1

0

You need to move to that directory. Try the following:

import os
os.chdir('C:\yt')
print os.getcwd() # confirm location
os.system("ffmpeg.exe -i test.mp4 newfilename.mp3")
Sign up to request clarification or add additional context in comments.

3 Comments

it's really a bad way of running a command in a separate directory.
I'm following the OPs approach
I know, but sometimes it's better not to, or explain then provide a better approach.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.