-2

I am curious if it possible to make custom terminal commands for a Python application, for example, if I were to make a slideshow program, one could into the command line INDEPENDENTLY from the program and type

C:\Users\foo> Slides

And get

SLIDES v0.0.0 Example 
Example command, example command

And if you typed start unnamed.slides

The slide program would open up and run slide project “unnamed”. Please ignore any factual errors in this if it were the actual commands for a program I’m just trying to get a point across.

  • it is possible not just for python. If you're really interested on this, I would advise to research about bash scripts. The idea would be to use a batch file to launch your python application. Then you would have to define an Environment Variable that would execute your application: https://stackoverflow.com/questions/3036325/can-i-set-an-environment-variable-for-an-application-using-a-shortcut-in-windows – akhavro Jan 24 '19 at 13:54

2 Answers2

2

You might want to take a look at the Argparse library that allows you to have command line options that are easily manageable. You can then use these options to execute certain parts of you program.

Luc Blassel
  • 394
  • 4
  • 15
0

All you need to do is use terminal input functions inside a while loop with code that responds to the input accordingly. To put it simply it would be like this:

 while True:
        user_input = input('command: ')
        # do whatever with the user input here.
Lucas Franceschi
  • 398
  • 6
  • 12
  • Yes, that would work, however I do not want to command line to open with the program. For example, one can open a file with Sublime Text 3 using subl foo.py – get_scripted Jan 24 '19 at 13:54
  • Well that isn't said at all in your question, in fact you actually say that the script would be called from the terminal. Overall (and to understand why your question was downvoted) I think you should read this: https://stackoverflow.com/help/how-to-ask (Edit: grammar) – Lucas Franceschi Jan 24 '19 at 14:00