从python内部执行命令行程序 [英] Executing command line programs from within python

查看:176
本文介绍了从python内部执行命令行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

在Python中调用外部命令

m建立一个将要操作(pad,mix,merge等)声音文件的Web应用程序,我发现 sox 正是我想要的。 Sox是一个linux命令行程序,我感到有点不舒服,让python web应用程序在我的服务器上启动新的sox进程,每个请求。

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.

示例:

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.

所以我的问题是,从python(或任何脚本语言)运行命令行程序的最佳做法是什么? )web app?

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 更好。

这篇关于从python内部执行命令行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆