Sie sind auf Seite 1von 5

LAB1: Command Line Interface (CLI)

system programming lab.

______________________________________________________________________________________

Objective: 1- Learning the behavior and the use of the Command Line Interface , its basic commands, environment variables, devices, redirection, pipes, and batch files. 2- Learning to use the php script interpreter, and compiler. IMPORTANT: You are required to read all this document carefully and execute every procedures enclosed in a box like this one 1- Basic Shell commands: The shell is a process (i.e. a program after being loaded) which provides the basic needs of a user interface to the operating system. It could be a GUI application, like MS windows Desktop interface, or a text mode application like the DOS shell (or CLI). A CLI provides a set of internal and external commands for navigating the file system tree, executing other programs, and various other utilities, where internal means that it is built-in the shell program (cmd.exe) , and external means it is another program loaded as a child process of cmd.exe. (The loading process, which is cmd.exe, is called the parent process). 1.1 Invoke a DOS shell by clicking the Command Prompt Accessories menu. option from the

You will get a text mode application window (called "console"), like this

The shell prompt: It is a string displayed by the shell to indicate that it is ready for accepting user commands. In the previous example, the prompt is formed by the name of the "current working directory" , which is D:\ (i.e. the root directory of drive D:) followed by a > . 1.2. Type help beside the command prompt, to get a listing of the available commands with one line descriptions as shown below, like this:

1.3 Study (read the help) and try out the following commands: File and directory commands:
cd, dir, mkdir, rmdir, type, copy, rename, move, del Pattern matching: find, sort start, mem (other network tracert, netstat, telnet, nslookup,..)

Utilities:

utilities which will be used later are, ping,

(Note: to get help on any command, type the command name followed by a space and /?) , for example:

Also note that file names and directory names containing space should be enclosed between double quotes "file name ". _______________________________________________________________________

2- Shell Variables: (Also called environment variables)


Variables can be defined using the set command. The variable value can be used in shell commands, and in shell scripts (i.e. batch files), by enclosing the variable name between a pair of % sign.

2.1 For example. Try the following:

Note that shell variables are not case sensitive, which means that myvar, MyVar and myvAR are all the same. You can view all the variables defined by issuing the set command without any arguments. (See the example below). Shell variables are used for several purposes, most importantly: 1 For passing information among different processes in the system, i.e. for Interprocess Communication (IPC). For this purpose, a copy of the environment variables is made available to every program executed by the shell. For example, the %java-home% variable is defined by a shell process to pass the name of the directory containing the java runtime environemnt (jre) to the java virtual machine. 2 As a shorthand for long file pathnames (i.e. alias) in the shell or in other programs. 3- As normal variables in shell programming. The variable path is used by the shell itself to identify the directories that should be searched to find the files used in shell commands, where the search goes from left to right in the same order of directories listed in the path. For example, in the shown listing , if two files with the same name "file1.exe" exist in D:\WINNT\ and D:\WINNT\system32 then D:\WINNT\system32 \file1.exe will be taken because it comes first in the path.

2.2 Copy the php4 and php5 folders to your hard drive. Modify the path by adding the directory c:\php5 to it as follows C:\>set path=%path%;C:\php5

verify that the path has changed by typing the new value using echo as follows:

C:\>echo %PATH% Now you can refer to files in C:\php5 from any other directory, for example you can execute the following php script from the root directory: 2..3 Write the following script in a file named script1.php using Notepad, and store it in a new folder C:\myphp <?php print(this is my first script\n); ?> then change directory to myphp and run the script from the command line by typing C:\myphp>php script1.php this is my first script C:\myphp> Where the program php.exe is the php script interpreter in the directory C:\php5, which is discussed in detail in section 7 below.

3- Pipes:
A pipe is another important means for interprocess communication, and it is basically a one directional FIFO buffer which can be written into by one process and read by another process. A pipe can be created in the shell using the vertical bar character | , for example You can search for all executable (.exe) files in the windows systems32 with creation date in the year 2006 by typing dir *.exe | find "/2006" and get all lines containing the substring "/2006" as shown below: 3.1. Use dir and find communicating through a pipe to search for executable

programs created in the windows\system32 directory in September (the 9 th month) 2006.

Das könnte Ihnen auch gefallen