standard in must be a tty Python script removing Sudo

元气小坏坏 提交于 2020-01-07 02:56:25

问题


I am trying to run the command

"sudo service awslogs start" 

from a python script. I cannot use 'sudo' so I change the command to

"su -c 'service awslogs start'"

but that does not seem to work either. I still get the error

su: user if=/dev/null does not exist

or

standard in must be a tty

Any ideas as to how to fix this?


回答1:


sudo -S reads from stdin, see man sudo:

 -S, --stdin
     Write the prompt to the standard error and read the password from the
     standard input instead of using the terminal device.  The password must be
     followed by a newline character.

You can also change /etc/sudoer to allow your user to run the specific command without sudo.



来源:https://stackoverflow.com/questions/37706171/standard-in-must-be-a-tty-python-script-removing-sudo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!