Subprocess.call doesn't work in PyCharm (linux)

Here's the program:

if os.name == 'posix' and getpass.getuser() != 'root':
  from subprocess import call

  call(["sudo", sys.executable, os.path.realpath(__file__), "--root-install"])

      

When I run it from terminal it works fine:

> [sudo] Password for user:

      

But when I run it from PyCharm, the terminal just stays blank.
I also tried installing stdin=sys.stdin, stdout=sys.stdout

manually, but that didn't change anything.

What am I doing wrong here?

+3


source to share


1 answer


PyCharm and IDEs usually don't like inputs getpass

. Since it sudo

prompts for a password this way, it cannot be launched from the IDE's redirected console.

Redirecting stdin

from Popen

won't change anything either.



Workaround: run the command sudo

from terminal. Example with xterm

(sorry, I don't know much about today's terminals):

call(["xterm","-e","sudo", sys.executable, os.path.realpath(__file__), "--root-install"])

      

+1


source







All Articles