User:Kenny: Difference between revisions
No edit summary |
No edit summary |
||
Line 7: | Line 7: | ||
== Command Line Interface == |
== Command Line Interface == |
||
The Command Line Interface of an operating system provides the most basic, but also a very powerful method of controlling the system. When writing an operating system, you should consider writing a command line interface after you have have a stable kernel, can output to the screen, and can read from the keyboard. |
|||
The Command Line Interface of an operating system is very important (... preamble) |
|||
The command line interface itself is split into two components, the command interpreter (also called the shell) |
The command line interface itself is split into two components, the console, and the command interpreter (also called the shell) itself. |
||
⚫ | |||
⚫ | The command interpreter is no different to any other command line tool, it expects a standard input stream, a standard output stream, a standard error stream, and a set of environment variables. Its task is to write a prompt to the standard out, read characters from the input stream, interpret them, run a program if necessary, then present another prompt. |
||
The console, or terminal, is the environment which runs command line programs. It provides a standard input stream, a standard output stream, a standard error stream, and a set of environment variables. |
|||
⚫ | The console itself, or terminal, is responsible for providing the input and output streams. In the simplest system, it takes the input from the keyboard and writes the output to the screen. In more complicated systems, there can be multiple consoles using the keyboard and the screen with a window for each, or consoles that use a serial port, or consoles that input from the keyboard and output to the printer. |
||
In a basic system, the standard input device is the keyboard, and the standard output and error streams go to text on the screen. |
|||
⚫ | |||
⚫ | |||
⚫ | The command interpreter is no different to any other command line tool, it expects a standard input stream, a standard output stream, a standard error stream, and a set of environment variables. Its task is to write a prompt to the standard out, read characters from the input stream, interpret them, run a program if necessary, then present another prompt. |
||
The console, or terminal, is the environment which runs command line programs |
|||
⚫ | The console itself, or terminal, is responsible for providing the input and output streams. In the simplest system, it takes the input from the keyboard and writes the output to the screen. In more complicated systems, there can be multiple consoles using the keyboard and the screen with a window for each, or consoles that use a serial port, or consoles that input from the keyboard and output to the printer. |
||
⚫ | |||
Line 29: | Line 30: | ||
The command interpreter itself is no different. When run, it goes into a loop where it outputs a prompt to stdout then waits for a command to be entered on stdin, it then runs the command, and goes back to display the next prompt. It does this until it's given a command to exit. |
The command interpreter itself is no different. When run, it goes into a loop where it outputs a prompt to stdout then waits for a command to be entered on stdin, it then runs the command, and goes back to display the next prompt. It does this until it's given a command to exit. |
||
== Writing a Command Line Interpreter == |
Revision as of 23:55, 6 March 2013
Command Line Interface
The Command Line Interface of an operating system provides the most basic, but also a very powerful method of controlling the system. When writing an operating system, you should consider writing a command line interface after you have have a stable kernel, can output to the screen, and can read from the keyboard.
The command line interface itself is split into two components, the console, and the command interpreter (also called the shell) itself.
Console
The console, or terminal, is the environment which runs command line programs. It provides a standard input stream, a standard output stream, a standard error stream, and a set of environment variables.
In a basic system, the standard input device is the keyboard, and the standard output and error streams go to text on the screen.
In C, the standard input stream (referred to as stdin), the standard output stream (stdout) and the standard error stream (stderr) are FILE structures. The stdin stream is read using the fread() function, and the stdout and stderr streams are written to using fwrite() or fprintf().
The command interpreter is no different to any other command line tool, it expects a standard input stream, a standard output stream, a standard error stream, and a set of environment variables. Its task is to write a prompt to the standard out, read characters from the input stream, interpret them, run a program if necessary, then present another prompt.
The console itself, or terminal, is responsible for providing the input and output streams. In the simplest system, it takes the input from the keyboard and writes the output to the screen. In more complicated systems, there can be multiple consoles using the keyboard and the screen with a window for each, or consoles that use a serial port, or consoles that input from the keyboard and output to the printer.
Command Interpreter
All command line tools operate in very much the same way. They expect to be provided with a standard input stream, a standard output stream, a standard error stream, and a set of environment variables. Each tool reads characters from the standard input (usually the keyboard), performs some task, outputs information to the standard output or standard error streams (usually the screen), then exits.
The command interpreter itself is no different. When run, it goes into a loop where it outputs a prompt to stdout then waits for a command to be entered on stdin, it then runs the command, and goes back to display the next prompt. It does this until it's given a command to exit.