Using Python to execute cmd commands

329
May 01, 2018, at 00:57 AM

Hello i have been playing around with python recently and have been trying to learn how to control external peripherals and i/o ports on my laptop.

I have been trying to disable USB ports and disable my network adapter. However when i run my program it does not work. The code does not have a specific syntax error but when it is ran nothing happens.

import subprocess

def main():
    print("PROGRAM STARTED")
    subprocess.call(["runas", "/user:Bradley", "cmd.exe /c netsh interface set interface '*' admin=disable"])
    print("Program Exited")

if __name__ == "__main__":
    main()
Answer 1

I think you should try to run such commands as admin in windows. This might help: https://social.technet.microsoft.com/Forums/windows/en-US/05cce5f6-3c3a-4bb8-8b72-8c1ce4b5eff1/how-to-run-a-program-as-adminitrator-via-the-command-line?forum=w7itproappcompat

You can also modify your command to print the output in stdout to debug easily.
print subprocess.check_output(['runas','/user:Bradley', "cmd.exe /c netsh interface set interface '*' admin=disable")

Rent Charter Buses Company
READ ALSO
python, tkinter: create several checkbuttons and retrieve checked ones

python, tkinter: create several checkbuttons and retrieve checked ones

i am trying to create checkboxes for elements from a list, but since the list is subject to changes, i cannot proceed like this:

210
Tabs don't work in python anaconda repl on windows

Tabs don't work in python anaconda repl on windows

This is what I get when I press tab anywhere in the consoleSpaces are okay

300
python: reload module inside function

python: reload module inside function

i have a configuration file in python that can be changed while the main script is running, so i need to reload it

218
Django Rest Framework File Upload Api

Django Rest Framework File Upload Api

Iam new to djangoI need to upload a file using the Rest Framework API

355