Skip to content

Instantly share code, notes, and snippets.

@imryan
Last active December 23, 2015 08:29
Show Gist options
  • Save imryan/6608306 to your computer and use it in GitHub Desktop.
Save imryan/6608306 to your computer and use it in GitHub Desktop.
Used at my school to execute shell scripts.
# Python 2 Shell Executor
# September 18, 2013
# Ryan Cohen
import socket, sys
from subprocess import call
def main():
print "\nPython 2 Shell Executor"
ip = socket.gethostbyname(socket.gethostname())
print "Your internal IP:", ip, "\n"
print "[1] Execute Command\n[2] Exit"
choice = raw_input("\n> ")
if choice is "1":
get_input()
elif choice is "2":
sys.exit()
else:
main()
def get_input():
command_name = raw_input("\ncommand_name> ")
command_args = raw_input("command_args> ")
if not command_args:
call(command_name, shell = True)
main()
else:
call([command_name, command_args])
main()
main()
# Python 3 Shell Executor
# September 18, 2013
# Ryan Cohen
import socket, sys
from subprocess import call
def main():
print("\nPython 3 Shell Executor")
ip = socket.gethostbyname(socket.gethostname())
print("Your internal IP:", ip, "\n")
print("[1] Execute Command\n[2] Exit")
choice = input("\nchoice> ")
if choice is "1":
get_input()
elif choice is "2":
sys.exit()
else:
main()
def get_input():
command_name = input("command_name> ")
command_args = input("command_args> ")
if not command_args:
call(command_name, shell = True)
main()
else:
call([command_name, command_args])
main()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment