Executing command line programs from within python

Possible Duplicate:
Calling an external command in Python

I'm building a web application that will is going to manipulate (pad, mix, merge etc) sound files and I've found that sox does exactly what I want. Sox is a linux command line program and I'm feeling a little uncomfortable with having the python web app starting new sox processes on my server on a per request basis.

Example:

import os
os.system('sox input.wav -b 24 output.aiff rate -v -L -b 90 48k')

This whole setup seems a little unstable to me.

So my question is, what's the best practice for running command line programs from within a python (or any scripting language) web app?

Message queues would be one thing to implement in order to get around the whole request response cycle. But is there other ways to make these things more elegant?


subprocess模块是从Python运行其他程序的首选方式 - 比os.system更灵活更好用。

import subprocess
#subprocess.check_output(['ls','-l']) #all that is technically needed...
print subprocess.check_output(['ls','-l'])

"This whole setup seems a little unstable to me."

Talk to the ffmpegx folks about having a GUI front-end over a command-line backend. It doesn't seem to bother them.

Indeed, I submit that a GUI (or web) front-end over a command-line backend is actually more stable, since you have a very, very clean interface between GUI and command. The command can evolve at a different pace from the web, as long as the command-line options are compatible, you have no possibility of breakage.


I'm feeling a little uncomfortable with having the python web app starting new sox processes on my server on a per request basis.

To me this seems to mean that he fears that, if he opens up his webserver to the public, that there's not a lot he can do to prevent his server resources from being consumed if 15.000 people decide to click on that button that will launch sox in this way.

链接地址: http://www.djcxy.com/p/13488.html

上一篇: 从Python运行Rsync

下一篇: 在python中执行命令行程序