-1

I have a line that I can use it with os.system like;

os.system("ffmpeg -i file.smh -acodec libmp3lame file.mp3")

Where ffmpeg is an exe file. But It creates a console window on the screen. Normally I hide the console window by the following:

import win32console,win32gui

win = win32console.GetConsoleWindow()
win32gui.ShowWindow(win,1)

I tried this but it didn't work. os.system still shows me the console window. So I have two options:

  • I need a way to hide the console window if I use os.system.
  • Or I need a subprocess equivalent of os.system.

I tried to use subprocess.Popen(["ffmpeg.exe -i file.smh -acodec libmp3lame file.mp3"]), but it can't find ffmpeg.exe.

How can I fix this?

Eryk Sun
  • 33,190
  • 5
  • 92
  • 111
GLHF
  • 3,835
  • 10
  • 38
  • 83

1 Answers1

1

subprocess.Popen(["ffmpeg.exe -i file.smh -acodec libmp3lame file.mp3"])

should be:

subprocess.Popen(["ffmpeg.exe", "-i", "file.smh", "-acodec", "libmp3lame file.mp3"])

The way you hade it, your OS will look for an executable named ffmpeg.exe -i ... rather than an executable named ffmpeg with -i, file.smh, ... as arguments

If splitting the arguments is problematic for some reason, you can use shlex.split to correctly split the arguments for you (It'll handle splitting quoted arguments correctly).

mgilson
  • 300,191
  • 65
  • 633
  • 696
  • Solved, thanks for the answer. – GLHF Jun 06 '16 at 05:30
  • This doesn't prevent creating a console window if ffmpeg.exe is a console application. I list several ways to hide the console in [this answer](http://stackoverflow.com/a/7006424/205580). – Eryk Sun Jun 06 '16 at 05:40
  • @eryksun You know what is funny? I actually used a way from your answer before you commented :). – GLHF Jun 06 '16 at 05:41