1

I am trying to install Debian package file by Python script.So I used the script below.

import os
os.system('echo %(passwd)s | sudo dpkg -i 34.deb' %locals())
After run the Python script,the package was not installed.It shown the below message.
sudo: no tty present and no askpass program specified
BUt when i try to install the package via terminall,It has been installed properly.The command which i gave in terminal is below.
sudo dpkg -i 34.deb
If you know,Let me.
Shurmajee
  • 987
  • 1
  • 11
  • 33
Viswa
  • 121
  • 1
  • 1
  • 7

2 Answers2

1

Seems sudo doesn't accept password by pipe, so following the documentation

Normally, if sudo requires a password, it will read it from the user's terminal. If the -A (askpass) option is specified, a (possibly graphical) helper program is executed to read the user's password and output the password to the standard output. If the SUDO_ASKPASS environment variable is set, it specifies the path to the helper program. Otherwise, if /etc/sudo.conf contains a line specifying the askpass program, that value will be used. For example:

                   # Path to askpass helper program
                   Path askpass /usr/X11R6/bin/ssh-askpass

If no askpass program is available, sudo will exit with an error.

you should pass with the -A flag an askpass program.

EDIT: seems that sudo accept password from stdin, use the -S flag.

gipi
  • 2,225
  • 17
  • 25
1

python too have the subprocess Module

import subprocess as sp
sp.call(["sudo","dpkg","-i", "some.deb"])

Must work

you can add each parameter

lindosekai
  • 168
  • 8