16.6. Running Programs from the Terminal

Quickly moving through our filesystem is just one benefit of using the terminal. We can also run our code inside of the terminal and see its output.

The commands for running a program in the terminal vary widely based on the coding language of that program. For this course, we will focus on Python.

Example

In our online repl.it and Trinket editors, we execute our programs by clicking the Run button. If we saved the code on our computer instead, we could run them from the terminal by typing python file_name.

We will explore this idea in the next chapter.

16.6.1. Exiting Programs

Let’s say there is an error in our code, like an infinite loop. If we launch the program from the terminal, how do we get it to stop?

The repl.it and Trinket editors also include a Stop button for just this type of situation. The matching action for the terminal is Control+c. Pressing both keys at the same time will usually stop a process that is currently running. If that doesn’t work, try entering the exit command to stop the program.

If Control+c and exit don’t work, ask the teacher for help!