yspreen
yspreen

Reputation: 1981

subprocess.call not working 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 the terminal it works fine:

> [sudo] Password for user:

But when I run it from PyCharm the terminal just stays blank.
I have also tried setting stdin=sys.stdin, stdout=sys.stdout manually, but that did not change anything.

What am I doing wrong here?

Upvotes: 3

Views: 797

Answers (1)

Jean-François Fabre
Jean-François Fabre

Reputation: 140188

PyCharm and IDEs generally don't like getpass-like inputs. Since sudo asks for the password in such a way, it's not runnable from a redirected IDE console.

Redirecting stdin from Popen won't change anything either.

Workaround: run the sudo command from a terminal. Example with xterm (sorry, I don't know much about nowadays terminals):

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

Upvotes: 1

Related Questions