How to give input streams in python?

后端 未结 2 1815
既然无缘
既然无缘 2021-01-21 09:54

i\'m uninstall some packages in Linux via python os module my code like

def uninstallZdev():
    print \'Uninstallation as a Super User\'
    system(\'apt-get re         


        
2条回答
  •  攒了一身酷
    2021-01-21 10:29

    Configure apt-get not to ask (see the apt-get man page:

    apt-get --assume-yes remove xxx
    

    For tools that cannot be configured, use pexpect to steer the process. pexpect lets you listen for output from a subprocess, and send input based on a simple API:

    import pexpect
    
    ag = pexpect.spawn('apt-get remove xxx')
    ag.expect('Do you want to continue')
    ag.send('Y')
    ag.wait()
    ag.close()
    

提交回复
热议问题