Member Avatar for sravan953

Hey guys...

I was recently working on a program, which opens a music file using Windows Media Player...so I tried:

subprocess.call("C:\Program Files\Windows Media Player\mplayer2.exe",loc)
# Where 'loc' is the location of the file

But then I got to know that it won't work and that I have to use:

subprocess.call(["C:\Program Files\Windows Media Player\mplayer2.exe",loc])
# Where 'loc' is the location of the file

But my question is, why the square brackets?

Thanks guys! :)

Recommended Answers

All 2 Replies

Refer to documentation here.

The first argument contains your arguments for the process itself so it needs to be a single element (list, tuple, etc). The remainder of parameters get passed to the Popen init function. Refer here to the remainder of items you can pass using **kwargs.

lol dude, because subprocess.call takes a list as it's first arg!

filename = 'song.mp3'
myList = ['myprog.exe',filename]

subprocess.call(myList)

Definetly look up the subprocess module, there's a whole lot more you can pass to call() that will help you direct your output, etcetera.

You may want to look into the Popen class if you are serious about getting back your output.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.