views:

575

answers:

3

Hello, 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.

+3  A: 

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
+1  A: 

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

Thanks

Aditya

Aditya Shukla
A: 

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