I am trying to execute the bash script while :; do afplay beep.wav ; done command from a python script, but be able to kill it afterwards.
I tried:
process = subprocess.Popen("exec while :; do afplay %s ; done" % fileName, shell=True, executable='/bin/bash')
as this answer suggests, but the above doesn't work for me. (The script doesn't run.)
How can I run while :; do afplay beep.wav ; done from python and kill it at any point after it is started?
EDIT: just noticed that exec >(while :; do afplay %s; done) will launch the script, but now process.kill() won't kill it.
help execinstead ofman exec, sinceexecis a builtin. Then you'll see thatexecexecutes commands. If you think about it a little bit, it doesn't make sense toexecnon-external commands;). What are you trying to do?while :; do afplay beep.wav ; donecommand from a python script, but be able to kill it afterwards. This answer shows an easy way to kill a bash script from python, and I tried to copy it but it didn't work.exec >(...)is not what you want at all, it's not even semantically correct.execand other horrible hack. What's your OS?