1

I'll start by saying that I am very, very new to Python.

I used to have a Windows/Dos batch file in order to launch Mencoder with the right set of parameters, without having to type them each time.

Things got messy when I tried to improve my script, and I decided that it would be a good opportunity to try coding something in python.

I've come up with that :

#!/usr/bin/python
import sys, os

#Path to mencoder
mencoder = "C:\Program Files\MPlayer-1.0rc2\mencoder.exe"
infile = "holidays.avi"
outfile = "holidays (part1).avi"
startTime = "00:48:00"
length = "00:00:15"

commande = "%s %s -ovc copy -oac copy -ss %s -endpos %s -o %s"
os.system(commande % (mencoder, infile, startTime, length, outfile))

#Pause
raw_input() 

But that doesn't work, windows complains that "C:\Program" is not recognized command.

I've trying putting some "\"" here and there, but that didn't help.

Manu
  • 4,410
  • 6
  • 43
  • 77
  • This may be a problem with windows. Without quotes around the in and out filenames, the command works. Thanks for the single quote and "r" tips, I'll ask another question if I run into an interesting problem. – Manu Jul 07 '09 at 07:21
  • that's weird. infile = 'holidays.avi' works, but not infile = r'"holidays.avi"' – Manu Jul 08 '09 at 13:09
  • ... enven though mencoder = r'"C:\Program Fil(...)"' works fine. – Manu Jul 08 '09 at 13:09

4 Answers4

4

Python have two types of quotes, " and ' and they are completely equal. So easiest way to get quotes in a string is to say '"C:\Program Files\MPlayer-1.0rc2\mencoder.exe"'.

Using the raw prefix (ie r'"C:\Program Files\MPlayer-1.0rc2\mencoder.exe"') is a good idea, but that is not the error here, as none of the backslashes are followed by a letter that is an escape code. So your original string would not change at all by having an r in front of it.

Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251
1

use two quotes instead of one if you are doing on windows.

"\\"
yhw42
  • 3,334
  • 2
  • 27
  • 24
1

I'm new to Python but I know when ever I see that problem, to fix it, the file (executable or argument) must be in quotes. Just add \" before and after any file that contains a space in it to differentiate between the command-line arguments. So, that applies to your outfile variable as well. The code should look like this...

#!/usr/bin/python
import sys, os

#Path to mencoder
mencoder = "\"C:\Program Files\MPlayer-1.0rc2\mencoder.exe\""
infile = "holidays.avi"
outfile = "\"holidays (part1).avi\""
startTime = "00:48:00"
length = "00:00:15"

commande = "%s %s -ovc copy -oac copy -ss %s -endpos %s -o %s"
os.system(commande % (mencoder, infile, startTime, length, outfile))

#Pause
raw_input()
Mark
  • 11
  • 1
0

You can even put the mencoder.exe into a directory which doesn't have a space char inside it's name (opposed to Program Files).

bob
  • 1