How to hide output of subprocess in Python 2.7

前端 未结 5 1277
无人及你
无人及你 2020-11-22 01:14

I\'m using eSpeak on Ubuntu and have a Python 2.7 script that prints and speaks a message:

import subprocess
text = \'Hello World.\'
print text
subprocess.ca         


        
5条回答
  •  天命终不由人
    2020-11-22 01:55

    As of Python3 you no longer need to open devnull and can call subprocess.DEVNULL.

    Your code would be updated as such:

    import subprocess
    text = 'Hello World.'
    print(text)
    subprocess.call(['espeak', text], stderr=subprocess.DEVNULL)
    

提交回复
热议问题