Using sudo with Python script

前端 未结 11 2279
轻奢々
轻奢々 2020-11-22 15:10

I\'m trying to write a small script to mount a VirtualBox shared folder each time I execute the script. I want to do it with Python, because I\'m trying to learn it for scri

11条回答
  •  [愿得一人]
    2020-11-22 15:53

    sudoPassword = 'mypass'
    command = 'mount -t vboxsf myfolder /home/myuser/myfolder'
    p = os.system('echo %s|sudo -S %s' % (sudoPassword, command))
    

    Try this and let me know if it works. :-)

    And this one:

    os.popen("sudo -S %s"%(command), 'w').write('mypass')

提交回复
热议问题