ITSE 1359 | PyThon Scripting

ACC

The Windows Command Prompt

Foreword

The command line (a.k.a. command prompt and cmd) has been a common interface on personal computers since the 1980's and remains a useful tool today. System and database administrators and web developers frequently rely on the minimalist, yet powerful, capabilities of the cmd.exe program. In this chapter, we will configure command.exe to run the Python interpreter.

Configuring the Command Prompt

Open a Windows command prompt. R-click on the icon on the taskbar and select Pin to taskbar.

Note: the Command Prompt is also known as: cmd.exe, Command Line, Command Window, etc.

Then, R-click on the Command Prompt icon again, R-click on the Command Prompt menu item and select Properties.

Set the Target: to: %windir%\system32\cmd.exe /k "cd c:\repos\itse1359"

The line says to open the command window (cmd.exe) and change the directory (cd). The /k option means to return to the cmd prompt after running the change directory command. Even though selecting OK should both apply the setting and close the dialog box, I have had better results by selecting Apply in Windows dialog boxes first and then selecting OK. There are other locations for cmd.exe such as C:\Windows\SysWOW64\cmd.exe

Note: The Start in: setting is disregarded when running as administrator. However, the directory must exist. More about that below.

If interested, to determine the location or your %windir%, use the echo command as shown. You can see that %windir% on my machine is C:\WINDOWS.

See the dialog box below. I recommend the following settings in Properties | Shortcut tab. Changing Start in: to a location most convenient for you and your workflow. Then select Advanced. Check the Run as administrator box and then OK.

You will need to add the following to the Target: setting:
/k "cd c:\repos\itse1359"

Note: The Start in: setting is disregarded when running as administrator. However, the directory must exist.

Many other settings can be configured in the Properties window. The Layout tab is selected which shows Window Size and Window Position settings.

Now, click on the cmd prompt icon on the taskbar to open it. Notice that the cmd prompt runs as administrator. Type the commands as shown for practice:

  1. python --version - the version of Python installed is shown
  2. python - shows Python information and opens the interpreter
  3. quit() - exit the interpreter
  4. cd .. - change to one directory level up
  5. cd .. - change to another directory level up
  6. cd repos\itse1359 - change to that directory
  7. cd - reports present working directory
  8. cd \ - change to root directory
  9. cd repos\itse1359 - change to that directory
  10. cd .. - change to one directory level up
  11. mkdir joebob - makes the directory joebob but it already exists

You can also apply property settings to future sessions of the Command Prompt by R-clicking on the header bar and selecting Properties. The setting changes made in the properties window will not apply to the current session but will apply to sessions that are open in the future. Notice, a soothing red was choosen for the background.

By the way, here's an MIT Course covering the command line.