how to issue sudo command using python -


i need issue "sudo service nginx status" check service status. have following:

import commands service output = commands.getoutput("sudo service nginx status") 

but getting "no tty present , no askpass program specified"

does understand this?

using commands.getoutput makes impossible provide user input required sudo command. name self explainable, interested in command output. stdin closed.

there several solutions this:

  1. turn off password verification sudo user launching python script. (read /etc/sudoers)

  2. pipe password: (unsafe/bad solution easy) "echo yourpass | sudo ..."

  3. check out subprocess.popen allowing provide input either console or file https://docs.python.org/2/library/subprocess.html#popen-constructor


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -