Skip to content

Instantly share code, notes, and snippets.

@NimishMishra
Created June 20, 2020 03:34
Show Gist options
  • Save NimishMishra/06c02f9cf4661042c5fc7ed297efa79a to your computer and use it in GitHub Desktop.
Save NimishMishra/06c02f9cf4661042c5fc7ed297efa79a to your computer and use it in GitHub Desktop.
def run_command(command):
command = command.rstrip()
try:
command.index("cd")
navigate_directory(command)
return "Directory changed to: " + str(os.getcwd())
except:
pass
try:
command.index("file")
output = file_handler(command)
return output
except:
pass
try:
output = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True)
except Exception as e:
output = "Failed to execute command " + str(e)
return output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment