Executing command line programs from within python
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puddle Jumping Looping
--
Chapters
00:00 Executing Command Line Programs From Within Python
00:49 Answer 1 Score 2
01:08 Accepted Answer Score 323
01:25 Answer 3 Score 28
01:58 Answer 4 Score 3
02:21 Thank you
--
Full question
https://stackoverflow.com/questions/4502...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #commandline
#avk47
ACCEPTED ANSWER
Score 323
The subprocess module is the preferred way of running other programs from Python -- much more flexible and nicer to use than os.system.
import subprocess
#subprocess.check_output(['ls', '-l']) # All that is technically needed...
print(subprocess.check_output(['ls', '-l']))
ANSWER 2
Score 28
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.
ANSWER 3
Score 3
If you're concerned about server performance then look at capping the number of running sox processes. If the cap has been hit you can always cache the request and inform the user when it's finished in whichever way suits your application.
Alternatively, have the n worker scripts on other machines that pull requests from the db and call sox, and then push the resulting output file to where it needs to be.
ANSWER 4
Score 2
I am not familiar with sox, but instead of making repeated calls to the program as a command line, is it possible to set it up as a service and connect to it for requests? You can take a look at the connection interface such as sqlite for inspiration.