Skip to content

Commit

Permalink
0.3.commandprompt
Browse files Browse the repository at this point in the history
  • Loading branch information
raviddog committed Jan 18, 2020
1 parent 7d3ed07 commit 2d82a7c
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 0 deletions.
Binary file added img/0/0.3.01-cmd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/0/0.3.02-cmd_dir.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/0/0.3.03-cmd_cd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/0/0.3.04-cmd_dir2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/0/0.3.05-cmd_cd_prev.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/0/0.3.06-cmd_cd_dual.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/0/0.3.07-cmd_dir_mingw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/0/0.3.08-cmd_options.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/0/0.3.09-cmd_nopath.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/0/0.3.10-start_path.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/0/0.3.11-env_var.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/0/0.3.12-sys_path.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
126 changes: 126 additions & 0 deletions wiki/Section 0/0.3.CommandPrompt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# 0.3 - Windows Command Prompt

*If you already know how to use the command line, and are able to add the `C:\mingw-w64\mingw64\bin` directory to your path, you may skip this page.*

*If you know how to use the command line, but don't know how to edit your path or if you don't even know what the path is, [skip to here](#Adding-Mingw-w64-to-the-Path).*

## What is it

The command prompt is a way of performing tasks on your computer by typing commands into the system. This used to be how computers were used before the development of the mouse and graphical user interfaces. There are a couple reasons it's still used today:

- Simple to develop for
- Flexible and powerful
- Allows for easy automation

The third point is the most useful feature, but we're interested in the first point. Graphical interfaces can be complicated and we're not interested in dealing with them when we're just starting out. Additionally, you are *required* to use the command line in order to use our compiler, it simply has no graphical interface whatsoever.

> One of the situations in which you don't need the command line to compile is when using an IDE. Most IDEs allow you to compile and test your code just by clicking a button. We still want to learn how the command line works though.
## Getting Started

Open your start menu. Without clicking anything, type `cmd` and press enter. The black box of ye olde should appear again.

![command prompt window](https://github.com/raviddog/cpp-tutorial/blob/master/img/0/0.3.01-cmd.png "Command Prompt Window")

1. Previous output lines
- The Windows command prompt starts off with your version of Windows, as well as a Microsoft copyright message.
2. The "prompt"
- This tells you your current "working directory". This is the folder the commands you execute are going to be run in. For example, the command to create a new folder will create it inside this one.
- Note: the words "folder" and "directory" mean the same thing and are interchangeable.
3. Your text cursor
- You might not be used to looking at a text cursor like this. The cursor in modern word processors are a thin vertical line. However, the cursors of old are a short thick horizontal line at the base of the text.
4. Scrollbar
- This needs no explanation. Other than possibly why it starts off so long. I'm not so sure about this myself.

## Browsing around

Let's begin with a simple command. Type `dir` and press enter. A big list of entries should appear.

![dir](https://github.com/raviddog/cpp-tutorial/blob/master/img/0/0.3.02-cmd_dir.png "Output of the 'dir' command")

`dir` lists all the files and folders in the current working directory. From left to right, the columns are:

- Date that this file/folder was last modified
- Time that this file/folder was last modified
- Whether this entry is a folder or not.
- Folders should display `<DIR>`
- If this entry is a file, its size in bytes
- The file/folder name

It finishes with the total number of files and the total size of those files, alongside the total number of folders and the total space free on your storage drive.

After `dir` has displayed its output, the prompt will appear again, along with the text cursor after it. This is an indication that the command prompt is ready and waiting for another command.

Take a look at the list and pick a folder. I'm going to pick the Videos folder. Type `cd Videos`, replacing Videos with the name of the folder you chose, then press Enter.

![cd](https://github.com/raviddog/cpp-tutorial/blob/master/img/0/0.3.03-cmd_cd.png "Output of the 'cd' command")

Nothing appears to have happened, at first glance. However, our prompt has changed. We are now inside the Videos directory. Go ahead and run the `dir` command, and you'll see the contents of it.

![contents of our new directory](https://github.com/raviddog/cpp-tutorial/blob/master/img/0/0.3.04-cmd_dir2.png "Contents of our new directory")

If you scroll up to the top of the file list, you may notice two folders that don't seem to be real, one named with a single period and one with two periods. Those folders represent the current directory, and the one holding it, respectively. Try entering the command `cd ..`

![cd ..](https://github.com/raviddog/cpp-tutorial/blob/master/img/0/0.3.05-cmd_cd_prev.png "Changing to the previous directory")

We've just switched to the previous directory. Knowing these two commands should be sufficient to allow you to navigate to any folder on your computer.

## Actually doing stuff

While being able to look at your files is pretty cool, we can't actually do anything with them yet.

Run `cd ..` until your prompt merely displays `C:\>`. Then enter `cd mingw-w64\mingw64`. We've just moved through two directories at once. This works with the `..` as well, if you now run `cd ..\..` you'll end up back at C:\\

Take a look at the contents of the `mingw64` folder. I'm sure you remember the command for that.

![contents of the C:\\mingw-w64\\mingw folder](https://github.com/raviddog/cpp-tutorial/blob/master/img/0/0.3.07-cmd_dir_mingw.png "Contents of the C:\\mingw-w64\\mingw folder")

Notice that there's one `.txt` file amongst the folders. Let's try opening it. Simply type the name of the file, `build-info.txt` and press Enter. Notepad should open up, displaying the file as if you'd opened it in Windows Explorer.

Cool, so we can open files. Actually we can run programs too. Try entering the command `notepad`. This runs the Notepad program, just as if you'd selected it in the Start Menu.

## Command Line options

While in the `C:\mingw-w64\mingw64` folder, enter the command `notepad build-info.txt`. This time, Notepad launches and opens the build-info file for us.

![notepad build-info.txt](https://github.com/raviddog/cpp-tutorial/blob/master/img/0/0.3.08-cmd_options.png "notepad build-info.txt")

The `build-info.txt` part of that command is something known as a *command line option*. It is an additional piece of information that we've passed on to the program when we opened it. Command line options are not restricted to filenames, in fact developers can write their programs to take whatever options they want.

Our compiler does not have a GUI. If you run it from Windows Explorer, nothing will happen. Instead, we need to tell it which file contains our code, and what the resulting program should be called. This information is provided via command line options.

## The Path

You may recall on the previous page that we opened a Command Prompt by opening a file called `mingw-w64.bat`. Then we typed `gcc -v` and got a bunch of stuff out. Why did we open it that way instead of from the start menu?

Try running `gcc -v` now. You may notice something different.

![gcc not recognised](https://github.com/raviddog/cpp-tutorial/blob/master/img/0/0.3.09-cmd_nopath.png "GCC is not recognised as a command")

Windows can only open programs when it can find them. By default it looks inside your current working directory. There is also a system setting that lists a bunch of folders to look inside. This setting is called the Path. We could just always go to the directory our compiler is in to run it, but that's hugely inconvenient, since this also affects files, which we'll see on the next page. Instead, we're going to have to add our compiler's directory to the Path.

## Adding Mingw-w64 to the Path

Open your start menu and type `path`

![Start menu Path](https://github.com/raviddog/cpp-tutorial/blob/master/img/0/0.3.10-start_path.png "Path setting in the Start Menu")

The option **Edit the System Environment variables** should appear. Click it. In the window that pops up, click on the **Environment Variables** button in the bottom right.

![Environment Variables](https://github.com/raviddog/cpp-tutorial/blob/master/img/0/0.3.11-env_var.png "Environment Variables")

In the resulting window, find the `Path` entry under the **System Variables** section. Highlight it and click **Edit**.

![System Path](https://github.com/raviddog/cpp-tutorial/blob/master/img/0/0.3.12-sys_path.png "System Path")

In the next window, click the **New** button in the top right. A new entry should appear in the list. Paste in `C:\mingw-w64\mingw64\bin` , then press Enter twice. Hit **OK** on the rest of the windows, then restart your computer. Once that's done, you can open up the command prompt (open the Start Menu and type `cmd`) and try running `gcc -v` again. This time you should get the big chunk of text.

> ### Note
>
> If **Edit the System Environment variables** doesn't appear when you search `path`, open up File Explorer. Right click on **This PC** on the left, and select **Properties**. In the next window, click **Advanced System Settings** on the left. This should bring up the correct window.
> ### Second Note
>
> If you installed your Mingw-w64 compiler to a different folder, be sure to use that folder instead of the one I've written. It should be your chosen installation folder, with `\mingw64\bin` appended to the end. To be sure, open up that folder in Windows Explorer. It should have a big list of `.exe` files, one of them being `gcc.exe`
## [Next Page](0.4.Workflow)

0 comments on commit 2d82a7c

Please sign in to comment.