Background Process subprocess.Popen with Pipe

audio-recording, background, python, subprocess

Solution

If you don't want the main Python process to block while executing the subprocesses, simply don't call `p2.communicate()`. The calls to `subprocess.Popen()` don't block.

Problem

I'm trying to record and convert a stream with python using arecord. In the shell this is a command more or less like: ``` arecord -B 5000 -f dat | lame -m j -q 5 -V 2 - test.mp3 & ``` In Python I tried this with subprocess.Popen: ``` reccmd = ["arecord", "-B", "5000", "-f", "dat"] mp3cmd = ["lame", "-m", "j", "-q", "5", "-V", "2", "-", "test.mp3"] p = subprocess.Popen(reccmd, stdout=subprocess.PIPE) p2 = subprocess.Popen(mp3cmd, stdin=p.stdout) p2.communicate() ``` But I don't know how to include the "&" or something similar in the code to be able to stop the recording with a `killall arecord` command

Original source