I'm trying to run a shell script inside some python code, but I keep getting an error message.
Python script (test.py):
import os f = os.popen('/home/test/Downloads/record.sh') f.close()
Shell script (record.sh):
#!/bin/sh rec -r 16k -c 1 -p | sox -p output.wav silence 1 0.1 1% -1 0.5 1% &
When I run:
This is the error message that I get: FAIL sox: `-' error writing output file: Broken pipe
Running the shell script alone works fine (i.e. ./record.sh).
What am I doing wrong? Thanks.
EDIT BELOW: I have changed the shell script, so it looks like this (there is no longer any piping):
#!/bin/sh rec -r 16k -b 16 -c 1 output.wav silence 1 0.5 0.1% 1 1.0 0.1%
With Stefano's help I have the following Python script:
#!/usr/bin/python from subprocess import Popen, PIPE output = Popen(["sh", "/home/test/Downloads/data/recorder.sh", ], stdout=PIPE).communicate()
Do I still need the PIPE and communicate bits?
What do I need to change, so that the python script doesn't wait for recorder.sh to finish before moving on?