Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run python file with admin rights in pycharm

Tags:

python

I'm running this code for trying to ping a server on pycharm:

import subprocess as sp

ip = "216.52.241.254"
status,result = sp.getstatusoutput("ping -c1 -w2 " + ip)

if status == 0:
    print("System " + ip + " is UP !")
else:
    print("System " + ip + " is DOWN !")

print(result)

However the print(result) line always prints "Access denied. Option -c1 requires administrative privileges.". I've tried running pycharm as admin but it doesn't have any affect. How can I give admin privileges to the file?

like image 498
Alter Avatar asked Oct 25 '15 15:10

Alter


2 Answers

Startup pycharm as Administrator then all scripts will be ran as administrator.

From Windows start menu right click the Pycharm shortcut and select 'Run as administrator.' Optionally create a short and change the options to always Run as Administrator under the "Compatibility" tab.

like image 72
Ron Pedersen Avatar answered Sep 20 '22 10:09

Ron Pedersen


Simply run the PyCharm shortcut as administrator, and then PyCharm terminal will run with admin privileges.

See these images for referral,

For Desktop PyCharm Shortcut

For Start menu search of PyCharm Shortcut

like image 26
himanshu singh Avatar answered Sep 21 '22 10:09

himanshu singh