1

Possible Duplicate:
How do I execute a program from python? os.system fails due to spaces in path

I am trying to call a program (MP3gain.exe) in command line from python. my problem is that python puts a [' '] around the command that I am sending to command line, and dos doesn't appear to be able to interpret the command with that. Here is my code.

import os
import subprocess
import Editor

class normalize():
    def __init__(self, file):
        self.FileName = file

    def work(self):
        command = [ 'mp3gain /r /c' + self.FileName]
        subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)


if __name__ == "__main__":
    test = normalize("filename.mp3")
    test.work()

In case this helps, if I have dos print out the exit code, it is -2. Thanks for any help.

2
  • 3
    What do you mean python puts a [' '] around the command? You're not supposed to have an actual snake type the code for you, it's just the language name. Commented Nov 21, 2012 at 21:35
  • If your command line should be mp3gain /r /c filename.mp3 - have you tried command = ['mp3gain', '/r', '/c', self.FileName] ? (also mp3gain will have to be callable from the interpreter's working directory - otherwise, you may need to call the path for the full executable) Commented Nov 21, 2012 at 21:36

2 Answers 2

3

command should be a list of strings, with mp3gain as the first one, that is:

command = ['mp3gain', '/r', '/c', self.FileName]
Sign up to request clarification or add additional context in comments.

Comments

0

You can call a program by using os.system. For example in you program you can use:

os.system("mp3gain /r /c " + self.FileName)

1 Comment

os.system is old. It is recommended to use subprocess to replace all the old methods for running a process.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.