Popen a command that contains need to say yes for all outputs

前端 未结 2 1998
攒了一身酷
攒了一身酷 2021-01-22 11:47

I need to automate the following command

cmd=\"yes | vgremove \"

whenever I code this command with

Popen(cmd.spli         


        
相关标签:
2条回答
  • 2021-01-22 12:23

    Piping is a shell feature, so you'll need shell=True on that. What you're doing without shell=True is executing yes with arguments. yes never stops executing so the subprocess never returns.

    0 讨论(0)
  • 2021-01-22 12:29

    There is a much easier way in this case:

    Popen('vgremove -f <vgname>')
    

    As for your question specifically:

    p = Popen(cmd.split(), stdout=PIPE, stderr=PIPE, stdin=PIPE)
    p.stdin.write('yes')
    
    0 讨论(0)
提交回复
热议问题