Using sudo with Python script

前端 未结 11 2285
轻奢々
轻奢々 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 16:12

    subprocess.Popen creates a process and opens pipes and stuff. What you are doing is:

    • Start a process sudo -S
    • Start a process mypass
    • Start a process mount -t vboxsf myfolder /home/myuser/myfolder

    which is obviously not going to work. You need to pass the arguments to Popen. If you look at its documentation, you will notice that the first argument is actually a list of the arguments.

提交回复
热议问题