0
我試圖從python腳本執行bash腳本while :; do afplay beep.wav ; done
命令,但能夠在之後終止它。Python從子進程開始while循環時kill bash
我想:
process = subprocess.Popen("exec while :; do afplay %s ; done" % fileName, shell=True, executable='/bin/bash')
爲this answer建議,但上面並沒有爲我工作。 (該腳本不運行。)
如何從python運行while :; do afplay beep.wav ; done
並在啓動後的任意時刻將其殺死?
編輯:只注意到exec >(while :; do afplay %s; done)
將啓動腳本,但現在process.kill()
不會殺它。
因爲'exec'是一個內建函數,所以輸入'help exec'而不是'man exec'。然後你會看到'exec'執行_commands._如果你稍微想一下,'exec'非外部命令'')''是沒有意義的。你想做什麼? –
@gniourf_gniourf我試圖執行'while:;做afplay beep.wav;完成'python腳本的命令,但能夠在之後殺死它。 [這個答案](http://stackoverflow.com/a/13143013/3310334)顯示了一個簡單的方法來從Python中殺死一個bash腳本,我試圖複製它,但它不起作用。 – theonlygusti
然後在你的問題中明確所有這一切!你需要大量編輯你的問題! –