how to type sudo password when using subprocess.call?

前端 未结 2 1445
栀梦
栀梦 2020-12-17 01:04

i defined a function that switch my proxy settings every now and then, problem is that i want it to run in a loop without manual intervention. But when i execute the program

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-17 01:59

    Here you can execute a command sudo without interactive prompt asking you to type your password :

    from subprocess import call    
    
    pwd='my password'
    cmd='ls'
    
    call('echo {} | sudo -S {}'.format(pwd, cmd), shell=True)
    

提交回复
热议问题