在python命令行执行sudo命令
def test(): sudoPassword = 'test' command = '/opt/lampp/lampp stopmysql' str = os.system('echo %s|sudo -S %s' % (sudoPassword, command)) print str
或:
(status, result)=commands.getstatusoutput('echo %s| sudo -S %s' %(PASSWORD,cmd))
日行一善, 日写一撰