Wellcome to my blog!

Blog ini berisi segala informasi yang dapat menambah pengetahuan anda, mengocok perut anda, bahkan bisa membuat anda konak! hmmm...kalo yg ini bisa gak yah???
Tampilkan postingan dengan label tekhnologi. Tampilkan semua postingan
Tampilkan postingan dengan label tekhnologi. Tampilkan semua postingan

22 Juli, 2009

Ponsel Yang Tahan Direbus, Tahan Banting, Tahan Disiram Bensin

Juragan skalian pernah denger ga Ponsel Yang Tahan Direbus, Tahan Banting, Tahan Disiram Bensin ?????

Ini dia ponsel nya, cek this out...



Anda mungkin sudah mengenal nama Land Rover bukan? Nama yang terkenal dengan sebuah merek mobil yang sangat tangguh disegala medan penggunaan dan cuaca.
Nah seperti itu jugalah gambaran Ponsel Land Rover S1, tahan terhadap segala macam keadaan. Coba Anda bayangkan bila ponsel anda anda rebus sampai panas mendidih 100 derajat apa yang Anda bayangkan?





Hal ini tidak menjadi masalah bagi Ponsel Land Rover S1 yang memiliki ketahanan suku mulai dari minus 20 derajat celsius sampai 100 derajat celcius, sungguh tanggguh bukan?

Ponsel yang dijual dengan harga 250 Poundsterling atau sekitar Rp 4,5 Jutaan sudah mulai dipasarkan melalui jaringan ritel TESCO di Inggris negara asal ponsel tahan banting ini.

Ketahanan lain yaitu jatuh ke beton dengan ketinggian 6 kaki dan ketahanan hidup walau di dalam air sekalipun. Ponsel ini dilapisi dengan bahan karet dan sekarang di rekomendasikan untuk digunakan pada keperluan Militer.

Untuk menciptakan ponsel ini perusahaan Land Rover telah bekerjasama dengan perusahaan piranti lunak Sonim Technologies. Bulan lalu ponsel Land Rover S1 ini diluncurkan oleh Sir Ranulph Fiennes.

Ponsel ini memiliki internet browser, radio FM, sistem GPS, lampu senter dilengkapi dengan kamera tahan air yang dilengkapi blitz. Ketahanan baterai 500 jam siaga dan 18 jam waktu bicara.

Memiliki loudspeaker yang sangat kencang bila suatu saat digunakan pada suasana bising.

Casing Ponsel inipun terbuat bukan dari sembarang plastik dan karet namun bahan yang tahan terhadap cairan minyak seperti bensin serta air mendidih serat tahan tekanan dan guncangan juga gores.



Juragan berminat ????

Read More ..

21 Juli, 2009

Cara Mendapatkan Free account rapid*share Premium Gratis

Cara Mendapatkan Free account rapid*share Premium Gratis

Salah satu tempat yang memiliki database file terbesar adalah rapid*share. situs ini mengizinkan penggunanya untuk meng-upload atau men-download file pada servernya. Tetapi bagi yang ingin mendownload file dari rapid*share diberikan aturan yaitu :

Free user:
* harus menunggu antrian
* dibatasi hanya satu ip address yang bisa mendownload pada waktu yang sama
* tidak bisa menggunakan aplikasi download manager *) seperti flashget
* kecepatan downloadnya juga dibatasi.
* untuk upload ukuran file maksimal 200 MB.
* File akan dihapus jika dalam 30 hari tidak ada yang mendownload
* Tidak bisa melanjutkan download jika koneksi terputus.

Premium Account
* Maksimal file yang bisa di upload 2000 MB
* Dapat personal webspace sebesar 500 GB
* Trafik 80 GB/bulan
* Bisa menggunakan download manager
* Kecepatan tidak dibatasi
* dll

Untuk mendapatkan Free account rapid*share Premium tersebut bagi yang mampu bisa membelinya dengan harga 6,99 Euro/bulan. Tetapi Bagi yang ingin mendapatkan rapid*share Premium Account secara gratis nih saya Berikan trik-triknya dengan cara yang GRATIS, LEGAL dan HALAL untuk mendapatkannya, Sebenarnya sih tidak gratis juga, karena kita bener-benar membeli account lewat websitenya. Namun uang yang kita gunakan untuk membeli bukan dari kantong kita, melainkan dari jerih payah kita, maukan?

Nih coba di ikuti tata caranya:

Usaha kita itu adalah jadi responden lembaga jejak pendapat. Intinya adalah kita akan dibayar setelah melakukan serangkaian surveys (penilaian kita). jadi yang di maksud melakukan survey adalah menilai suatu website yang di berikan linknya oleh situs AWSurveys, setelah kita melihat sekilas web yang di tampilkan tadi berikan tanggapan menurut anda tentang web tersebut dan di tulis di kolom yang berada di bawah link yang di berikan tadi. setelah 2 web tadi telah kita berikan pendapat dilanjutkan mengklik tombol clik here to submit dan seterusnya hingga link yang di berikan AWSurveys tadi habis. Kalo rajin dan lagi beruntung (surveynya lagi banyak) sebulan kita bisa ngantongin antara $300 – $ 750 sebulannya. Uang yang dibayarkan kepada kita bisa di transfer ke account kita di PayPal. Setelah itu kita membeli account Premium rapid*share lewat account PayPal kita. Semuanya gratis dari internet.

Langkah – langkah mendapatkan rekening / account di PayPal:

1. Daftar account PayPal di http://www.paypal.com/
Tidak perlu memasukkan no kartu kredit jika ditanyai, karena kita menggunakan account PayPal untuk menerima uang. Pilih alternatif yang kedua (acount primer), sebagai pembeli dan penerima. Kita akan nerima dari hasil kerja menjadi responden dan akan membeli account RS.

2. Selanjutnya Klik dan daftar account di sini http://www.AWSurveys.com/HomeMain.cfm?RefID=nanangaje

Klik di “Create A Free Account” untuk mendaftar dan isi data kita yang lengkap. Setelah registrasi, lakukan survey yang telah disediakan. Anda akan mendapatkan USD $27 setelah pendaftaran dan survey pertama. Kalo rajin dan lagi beruntung (surveynya lagi banyak) sebulan kita bisa ngantongin antara $300 – $ 750 sebulannya

3. Setelah mendapatkan uang cukup, transferkan ke account PayPal anda.

4. Bikin account Rapid Share Premium dengan dibayar oleh account PayPal anda.

5. Download deh sepuasnya ampe meleduk lalu share ama kita-kita biar tambah rame forumnya.

6. Account PayPal bisa juga dipake belanja di mana aja yang nerima pembayaran dengan PayPal, Banyak koq, eBay, amazon dll.

7. Account PayPal ini bisa juga di tarik uangnya (hasil jerih payahnya) diambil tunai (ditransfer).

Semoga bisa membantu.

Blogged with the Flock Browser
Read More ..

Advanced Windows Shell Tutorial

Review of the Windows Shell

In the first lab, you learned the basics of using the Windows command shell. In this lab you will learn how to automate shell commands. You will create batch files consisting of sequences of commands that can be executed again and again. First, however, we will review the basic shell commands.

Exercise 1
Open a command shell window. Describe what you did to open it.

Exercise 2
In the command shell window, change to your personal directory. (If necessary, create it.) What commands did you issue?

Exercise 3
Inside your personal directory, create a subdirectory named advanced. What command did you issue?

Next, download this ZIP file and place it into the c:\yourname\advanced directory. (As always in this tutorial, c:\yourname denotes your personal directory. Be sure to substitute d:\jqsmith or c:\users\jqsmith or whatever your personal directory is called.)

To unzip a file, you can use the jar command. The jar command takes an option that describes the action you want to take, then the name of the compressed file. For example,

jar -xf bank.zip
extracts the files from the file bank.zip into the current directory. (The xf denotes extraction from a file.)

Exercise 4
Unzip the file bank.zip now. How many files were stored inside it? (Hint: dir)

{short description of image} NOTE: If you get a "command not found" error message when executing the jar command, then you need to specify the full path name of the jar.exe program, such as c:\j2sdk1.4.2\bin\jar.exe. You may need to spend some time looking for the jar.exe file, or ask a lab assistant. If you do this exercise on your own computer, make sure that the Java SDK is installed. You can download it from http://java.sun.com/j2se.

Batch Files

When you submit your homework by email, your instructor will probably ask you to zip up all homework files. A beginner would use a  program such as WinZip for this task. You know the drill. Click on the WinZip icon. Click, click, click, until you have added each file. Click, click, click, type the zip file name, click, click, and you are done. Did you need to make a last-minute change to a file? Do it all over again. And again.

You can do better than that. The command

jar -cf homework.zip *.java

makes a zip file called homework.zip that contains all Java files in the current directory. (The cf option denotes compression to a file.)

Maybe you also need to include some other files (such as Javadoc documentation and UML diagrams). Then the command gets longer.

jar -cvf homework.zip *.java *.html *.jpg

(The v option produces verbose output, listing the actions that the jar command takes.)

Rather than typing the command every time, you can place it into a batch file, and run the batch file as a single command. We will start with a simple version of such a batch file.

Start the Notepad program. Type in the following text:

@echo off 
rem Zip up source, HTML, images
jar -cvf homework.zip *.java *.html *.jpg

Then use the File -> Save as menu option to save the file as c:\yourname\advanced\zipup.bat.

{short description of image}
NOTE: Depending on the Windows configuration, the Notepad program may add a .txt extension to the file name, that is, zipup.bat.txt. (This evil and stupid behavior may be hard to spot unless you changed the Windows Explorer's evil and stupid default of "hiding known file extensions". You learned how to make that change in lab #1.) The remedy is to surround the file name in double quotes: "zipup.bat".

To execute the batch file, simply type its name:
zipup
In general, you execute the commands in a batch file by typing the name of the file (without the extension .bat).

Exercise 5
Run the zipup batch file now, in the c:\yourname\advanced directory. Before running the batch file, make sure that the directory contains a few Java files (from the preceding exercise). What is the result of running the batch file?

The first two commands of the start batch file are new commands. @echo off suppresses the display of each command on the screen as it is executed. A line starting with rem contains comments that are ignored by DOS.

Exercise 6
Comment out the line @echo off (by prefixing it with rem). Run the batch file. What is the difference?

Your instructor may ask you to run the Javadoc program to extract document comments before you submit your homework. The command is

javadoc *.java

Exercise 7
Enhance the zipup.bat file to automatically execute the javadoc program. Call the file zipup2.bat. What is the contents of the file now?

As you make more changes to the file, keep changing the name (zipup2, zipup3, etc.) Then you can submit the various versions for grading.

Batch File Arguments

Suppose you sometimes want to zip up your homework to hw1.zip, then to hw2.zip, or even to hw1_1728.zip. This can be easily done by modifying zipup.bat.

Change the filename homework.zip to %1.zip:

jar -cvf %1.zip *.java *.html *.jpg

When executing the batch file, you now need to supply the name of the zip file (without the .zip extension which is appended in the batch file). For example,

zipup3 hw1

Then the %1 is replaced by hw1. %1 is the first argument of the batch file, %2 is the second, and so on.

Exercise 8
How do you run the batch file to save your homework to hw1_1728.zip?


Exercise 9
Type zipup3 without an argument. What happens?


Let's modify the batch file to give an error message if no command line argument is specified.

Add the following lines to the batch file and name it zipup4.bat.

@echo off 
if "%1" == "" goto error
rem Zip up source, HTML, images
jar -cvf %1.zip *.java *.html *.jpg
goto end
:error
echo Usage: zipup4 filename    
Exercise 10
Now type zipup4 without an argument. What happens?


The if "a" == "b" command tests whether the strings a and b are equal. The goto command goes to a label. Each label starts with a colon (:). The echo command displays a message on the screen.

Environment Variables

The zipup batch file is quite useful, and you may want to put it to work for many assignments. But you now have a problem. Suppose you have worked on your homework in the directory c:\yourname\hw1. But the batch file is located in c:\yourname\advanced.

Exercise 11
Create a directory c:\yourname\hw1. Change to that directory. Copy all Java files (but not the batch file) from the c:\yourname\advanced directory, so that you can pretend that you just completed a homework assignment. What shell commands did you use?

Exercise 12
Now type zipup4 hw1. What happens?

The operating system cannot find the zipup4.bat file. After all, that file is in a rather obscure directory. The operating system only looks at certain places to locate executable files. These places include
  • the current directory
  • the c:\windows and c:\windows\system32 directories
  • any other directories that are referenced in the PATH environment variable
An environment variable is a variable that is used by the command shell to identify certain important settings.

Exercise 13
Type the command set. Look for the definition of the PATH variable. What result do you get?

The command set lists all environment variables. The PATH variable contains a list of directories, separated by semicolons. Minimally, the PATH will contain
c:\windows;c:\windows\system32
If you work in a computer lab, the lab administrator probably has added the directory for the Java commands (c:\j2sdk1.4.2\bin or something similar).

{short description of image} NOTE: Depending on your version of Windows, the environment variable may be listed as Path, not PATH. That's ok--in Windows, environment variables are not case-sensitive. However, it is considered good style to use uppercase letters for environment variables.

You sometimes want to add directories to the PATH so that the operating system can locate executable files in them. For example, let us enhance the PATH so that the command shell finds the zipup batch file.

Create a batch file myenv.bat that has the following contents:
@echo off
set PATH=c:\yourname\advanced;%PATH%
echo The PATH is now %PATH%
Be very careful with the spacing. There must be no spaces around the symbols = ; %. Only set and PATH are separated by a space.

The expression %PATH% denotes the current value of the environment variable PATH.

The command
set PATH=...
sets the PATH environment variable to the expression on the right hand side.

Exercise 14
Execute the myenv.bat batch file. What result do you get?

{short description of image} NOTE: In Windows XP, you can also execute the command set PATH=...;%PATH% directly on the command line. However, in older versions of Windows, the %PATH% expression works only inside a batch file. 


Exercise 15
Make sure that you are currently in the c:\yourname\hw1 directory. Now type zipup4 hw1. What happens? Why does the zipup command work now?

Another important environment variable is the CLASSPATH variable. It contains a list of locations in which the Java compiler and interpreter look for class files. Particularly for advanced Java programming, you will need to set the CLASSPATH variable.

We will show one example how this is done. The CheckStyle program checks whether a Java program follows good style conventions (no missing Javadoc comments, no public instance fields, etc.) CheckStyle itself is a Java program, so you start it by specifying its main class name. You specify a rule file with the -c option. Then specify the Java files that you want to check as additional parameters. For example,

java com.puppycrawl.tools.checkstyle.Main -c sjsu.xml BankAccount.java
Here, com.puppycrawl.tools.checkstyle.Main is the Main class in the com.puppycrawl.tools.checkstyle package. That class has a method public static void main(String[] args) that kicks off the CheckStyle program.

Exercise 16
Change to the c:\yourname\advanced directory. Download the file checkstyle-all-3.1.jar into that directory. Also download the file sjsu.xml and save it in the same directory. That file contains rules for the SJSU CS department style guide. Now type
java com.puppycrawl.tools.checkstyle.Main -c sjsu.xml BankAccount.java
What happens?

Unfortunately, the Java interpreter can't find the com.puppycrawl.tools.checkstyle.Main class. That class isn't in one of the standard places. By default, the Java interpreter looks for classes
  • in the rt.jar file of the Java runtime directory
  • in all jar files contained in the ext subdirectory of the Java runtime directory
  • in the directories listed in the CLASSPATH environment variable
  • or, if there is no CLASSPATH environment variable, in the current directory
But the com.puppycrawl.tools.checkstyle.Main file is contained inside the checkstyle-all-3.1.jar file. The remedy is to set the CLASSPATH to include that file:
set CLASSPATH=.;c:\yourname\advanced\checkstyle-all-3.1.jar

Note that the CLASSPATH contains the current directory (.).

Exercise 17
Execute the command for setting the CLASSPATH. Now type
java com.puppycrawl.tools.checkstyle.Main -c sjsu.xml BankAccount.java
What happens? Why does the command now work?

In general, you will want to set the CLASSPATH variable in a batch file such as myenv.bat.

Of course, the CheckStyle command is way too long to type each time you want to check on the quality of a source file. Let's turn it into a batch file.

Exercise 18
Write a batch file check.bat so that you can check the style of any Java file. For example,
check BankAccount.java
In your batch file, you need to specify the full path name for the jar file and the sjsu.xml file. Otherwise, your batch file won't work when it is called from another directory. Because the same directory name occurs twice, use an environment variable:
SET CHECKSTYLEHOME=c:\yourname\advanced
SET CLASSPATH=.;%CHECKSTYLEHOME%\checkstyle-all-3.1.jar
...
What is the contents of your batch file?

{short description of image} NOTE: You can avoid the use of the CLASSPATH environment variable by using the -classpath option for the javac and java commands. For example,
java -classpath c:\yourname\advanced\checkstyle-all-3.1.jar 
com.puppycrawl.tools.checkstyle.Main -c c:\yourname\advanced\sjsu.xml BankAccount.java
Of course, such a long command only makes sense inside a batch file.

You have just learned the best method for manipulating the PATH and CLASSPATH variables. Make yourself a batch file that sets the variables to the settings that you want. Then execute the batch file immediately after opening the command shell.

Alternatively, you can make permanent changes to the PATH and CLASSPATH variable. However, in a lab environment, you probably don't have the authority to do this. Moreover, when you work on different projects, you may want to have different settings, not one global setting. Simply make a separate batch file for each project and execute the appropriate file after opening a command shell.

{short description of image} NOTE: Occasionally, it does make sense to make permanent additions to the PATH. For example, after downloading the Java SDK, you should add the directory for the Java commands to the PATH. In Windows XP, open the control panel. Make sure it is in classic mode. Click the System icon, then on the Advanced tab, then on the Environment Variables button. Edit the PATH variable in the System Variables section. The same method works for Windows NT and Windows 2000.

.

.

.

{short description of image} NOTE:  For Windows 95, 98, and ME, you use a completely different (and more sensible) approach to change the PATH environment variable. Edit the file c:\autoexec.bat (or create it if it doesn't already exist). Then place the set PATH=...;%PATH% command inside that batch file. It is executed whenever your computer boots up.

.

{short description of image} NOTE: Globally setting the CLASSPATH variable (in the control panel or autoexec.bat) will only bring you grief in the long run. Don't do it. Set CLASSPATH in a project batch file, or use the -classpath option.

{short description of image} NOTE: If you use Windows 95/98/ME, you may run out of "environment space" if you set too many environment variables.  The remedy: In the shell window, click on the Properties button, then pick the Memory tab and set the Initial Environment to the maximum value (4096).

.

.

Redirection

Suppose you want to email a directory listing, perhaps to ask for help with a technical problem. How can you do it? The dir command shows the display of the directory on the screen. If it happens to fit on one screen, you can copy and paste it into your email program. But what do you do if the directory listing doesn't fit on one screen?

You can capture terminal output to a file, with the output redirection operator. The construct
command > file

sends the output of a command to a file.
 

Exercise 19
Execute the command
dir c:\windows > out.txt
Then look inside the out.txt file. What do you see? What is the last line in the file?

One useful application for redirection is automated grading of homework. Imagine you work as a grader for your professor. You get a bunch of zip files, one from each student. For each of the zip files, you want to go through the same steps:

  • Unzip the file
  • Compile the program
  • Run the program
  • Capture the output in a file
Why capture the output? You can then look at it when it is convenient, or email it to the professor or student.

Let's design such a batch file. We'll call it grade.bat. It takes two parameters: the name of the zip file (without the extension), and the class with the main method. For example,
grade hw1_1728 BankAccountTest

Exercise 20
What are the commands to unzip the file hw1_1728.zip, compile the Java source, run the BankAccountTest program, and capture the output in the file hw1_1728.txt? Hint: Use redirection: java ... > ...

Exercise 21
Now write the grade.bat file. Simply take the results from the preceding exercise and replace hw1_1728 with %1 and BankAccountTest with %2.  What is the contents of grade.bat?

Exercise 22
Make sure that both grade.bat and bank.zip are in the c:\yourname\advanced directory. Then run
grade bank BankAccountTest
What output file was created? What is the contents of that file?

Another useful redirection operator is >>. It appends the output of a program to a file. For example, you may first want to run CheckStyle on the submitted programs and capture the output in the report file, then append the output of the program run.
java -jar checkstyle-all-3.1.jar -c sjsu.xml *.java > homework.txt
javac *.java
echo ===Program Run=== >> homework.txt
java BankAccountTest >> homework.txt
Note the echo command. It produces a line of output, ===Program Run===. That line is appended to the homework.txt file.

Exercise 23
Add this enhancement to the grade.bat file and call the result grade2.bat. As before, make sure the file can be executed from any directory. (Note that we use a different method for invoking CheckStyle, with the -jar option. This option does not require you to set the class path.) What is the contents of grade2.bat now?

Finally, let us capture the compiler output in the homework report as well. Unfortunately, now we have a problem. Compiler errors are reported to the standard error stream, not the standard output stream. The > and >> commands only redirect  the standard output stream. The remedy is to use the 2> operator which redirects the standard error stream. (For historical reason, that stream is also known as stream #2.) 

javac *.java 2> homework.txt

There is also a 2>> operator to append the standard error stream output.

{short description of image} NOTE: The 2> operator does not exist in Windows 95/98/ME. For these versions of Windows, compile the following Java class:
import java.io.*;

public class Errout
{
public static void main(String[] args) throws IOException
{
Process p = Runtime.getRuntime().exec(args);
BufferedReader err
= new BufferedReader(new InputStreamReader(p.getErrorStream()));
String line;
while ((line = err.readLine()) != null)
System.out.println(line);
}
}

Then execute the following command:

java Errout javac MyProg.java > homework.txt

You can also supply the input to programs in a file rather than keying it in. This is useful when supplying program input for testing. The < operator redirects console input to a file. That is, whenever the program wants to read input, it grabs it from the file, not the keyboard.

Download and unzip the interest.zip file. Open the SavingsAccountTest program with the Notepad program and have a glance at it.

The test program asks the user to supply several values.

Exercise 24
Compile and run the SavingsAccountTest program. What balance do you get after 10 years with an initial deposit of $10,000 at 5% interest?

As a grader, you would not want to type in the same input values over and over. Therefore, let us place the program inputs into a file input1.txt.

Exercise 25
Create an input.txt file with three lines, one for each program input. Run the command
java SavingsAccountTest < input1.txt
Note that you no longer provide any keyboard input. What output do you get?

Input redirection only works with console input, not with input into dialog boxes. For that reason, the SavingsAccountTest program uses the BufferedReader class, not the JOptionPane class.

Some commands are specifically designed to work with input from the keyboard (thus allowing redirected input). The sort program is an example.

Exercise 26
Try the following:
dir c:\windows > out.txt
sort < out.txt
What is the result?

The sort program reads from standard input (that is, the keyboard or a redirected file). It is possible (although not very useful) to have sort sort some lines of keyboard input.

Exercise 27
Type sort and then the following lines.
Mary
had
a
little
lamb
Hit Enter after each line. When you are done, hit Ctrl-Z and Enter. Ctrl-Z is a special key that tells the shell to stop sending keyboard input to the program.
What is the result?

As you just saw, sorting a directory listing can be achieved in two steps. First capture the listing in a file (dir > out.txt), then sort the captured output (sort < out.txt). Because this combination is so frequent, there is a shortcut for it, called a pipe.

dir | sort 

This pipe, written with a vertical bar, runs dir, stores its output in a temporary file, then runs sort and redirects its input from that temporary file, and then automatically deletes the temporary file.

Another useful program that reads from standard input is more. The more program stops every screen full and waits for you to hit a key before continuing.

Exercise 28
Type the command
dir c:\windows | more
What happens?

You can pipe any sequence of commands together.

Exercise 29
Type the command
dir c:\windows | sort | more
What happens?

Error Level

Let's look at the grade.bat file again. Suppose a student submitted a file that doesn't even compile. Then we should abort the batch file after the call to javac, without trying to execute the program.

Every program returns an integer value, called the error level, to the operating system. By convention, a program returns the value 0 when it is successful and a non-zero value to indicate some kind of error. In your own Java programs, you can set the error level by calling

System.exit(level);
The Java compiler sets the error level to 0 when a program compiled successfully, and to a non-zero value otherwise.

You can test the error level of a program in a batch file.

javac *.java
if errorlevel 1 goto error
...
goto end
:error
echo Program didn't compile > %1.txt
:end

Exercise 30
Add this enhancement to your grading batch file and call the result grade3.bat. Test it by introducing an error in the BankAccount.java file: Change class to lass. Then create a new zip file bad.zip that contains the file with the error.
  1. What is the contents of grade3.bat
  2. What commands did you use to create the file bad.zip?
  3. What was the contents of bad.txt after you ran grade bad BankAccountTest?

The if errorlevel n command tests whether the error level is >= n. Thus, if you have a program that returns 1 for a mild error and 2 for a fatal error, then you want to first carry out a check if errorlevel 2, then if errorlevel 1.

Loops

You know how to make simple branches in batch files with commands such as

if "%1" == "" ...
if errorlevel 1 ...
if exist input1.txt ...

As you can see, you can do simple programming in batch files. For more advanced programming, you need the for construct.

There are two separate versions of for:

for %f in (*.java) do javac %f
for %d in (A,C,D) do dir %d:

The first for loop lets the variable %f run through all files that match the pattern *.java. The second for loop lets the variable %d run through the three choices A, C, D.

Variables in a for loop must always start with a % sign. However, inside a batch file, you must use two% signs, such as

rem this is inside a batch file
for %%f in (*.java) do javac %%f

Now let us put this technique to work in our grading batch file. We want to feed all input files of the form input*.txt to the program to be graded. That way, the grader can prepare an arbitrary number of files input1.txt, input2.txt, etc. Ideally, we would like to issue the command

for %%f in (input*.txt) do java %2 < %%f >> %1.txt

Sadly, this command does not work in all versions of Windows. In some Windows versions, you cannot mix the redirection operators with the for loop.

{short description of image}
NOTE: Incompatibilities between Windows versions are a vexing problem for authors of sophisticated batch files. Most shell users eventually give up in disgust and migrate to another shell such as the bash shell. In Windows, install the excellent Cygwin package to get a bash shell and a wealth of powerful command-line tools with well-defined behavior.

In this situation, you can solve the compatibility problem with trick. Write a second batch file gradehelper.bat that contains as its  single command the body of the for loop.

rem this is gradehelper.bat
rem %1 is the name of the output file (without extension)
rem %2 is the name of the program file (without extension)
rem %3 is the name of the input file (with extension)
java %2 < %3 >> %1.txt

Then the original batch file can call gradehelper:

rem this is grade4.bat
rem %1 is the name of the output file (without extension)
rem %2 is the name of the program file (without extension)
. . .
for %%f in (input*.txt) do call gradehelper %1 %2 %%f
. . .

(You use of call command to call a batch file from inside another batch file.)

Exercise 31
Add this enhancement to your grading batch file. Call the result grade4.bat. Test it by producing two files input1.txt and input2.txt with different inputs for the SavingsAccountTest program.
  1. What is the contents of grade4.bat?
  2. What was the contents of interest.txt after you ran grade interest SavingsAccountTest?
  3. How can you improve gradehelper.bat so that the outputs that belong to different program runs are separated from each other? (Hint: echo)

If you have trouble with this exercise, try using the echo command for debugging. For example,

echo gradehelper.bat is called with parameters %1 %2 %3
or
for %%f in (input*.txt) do echo Need to call gradehelper %1 %2 %%f

Exercise 32
The grade4.bat file grades a single homework submission. Suppose you are the grader, and you have to grade dozens of submissions, each of which has the form hw1_xyzw.zip, where xyzw is a four-digit number. Write a file gradeall.bat that grades all files and produces a combined report for all of them.
Hints:
  1. Modify the grading batch file so that the reports are all appended to a single report file. Call the result grade5.bat. Typical usage: grade5 hw1_xyzw.zip BankAccountTest report.txt. (Note that you will need to make some minor changes in grade5.bat because now %1 includes the .zip extension. You should use the same gradehelper.bat file as in the preceding exercise.)
  2. In gradeall.bat, loop through all zip files in the current directory and call grade5.bat for each of them. Typical usage: gradeall BankAccountTest report.txt
What are your gradeall.bat,and grade5.bat files?

Hopefully, these exercises have given you a feel for the power of automation. While it is undeniably challenging to automate a task for the first time, the effort is  repaid handsomely. It is fun to watch the computer do the same boring tasks over and over, particularly if you consider how much time it would have taken you to do it by hand.

In your programming and testing process, you carry out lots of repetitive steps. Automate them, and you will become more productive. You will also find that you would never attempt certain tasks without automation. For example, consider the task of testing your programs. Whenever you change a program, you should really test it again with a bunch of inputs. Do you do that? Probably not. What could be more tedious than typing in the same inputs over and over again? You now know that you can automate that task. Put a bunch of test inputs into files and write a batch file that automatically feeds them into your program. Test automation leads to higher quality programs.

For those reasons, all professional programmers are serious about automating their build and test processes. You have just learned how to use the command shell for basic automation tasks.

Blogged with the Flock Browser
Read More ..

Windows Shell Tutorial

Operating Systems, User Interfaces, and Shells


The operating system manages the resources of a computer, such as its internal memory, the disk drives, keyboard, monitor screen, mouse, printers, and network connections. People who use a computer to browse the web or play games have minimal contact with the operating system. Most of their time is spent with application programs.

These users tend to use the operating system only to fix problems, for example with a failed internet connection. The most recent versions of popular operating systems (such as Windows XP) have become very much oriented towards the consumer, hiding all but the most basic tasks from the casual user.

Computer programmers have more advanced needs than people who use the computer as a tool. Programmers need to compile and launch programs and automate recurring tasks. This tutorial is written for programmers who are already familiar with the basics of using a computer. 

If you have prior experience using a computer for playing games or writing reports and are now learning to program, you will need to learn more about your operating system. Some students are reluctant to embark on this effort, either because they feel that they already know how to use their computer, or because they already have their hands full learning about programming. However, that is a short-sighted attitude. Without knowing the operating system, many common programming tasks seem tedious or even impossible.

Operating systems come with two different kinds of user interface:

  • a graphical user interface or GUI
  • a command line interface, also called a shell

 Most computer users are familiar with the graphical user interface or GUI. Most GUI environments display a desktop that is populated with windows, icons and menus. You use apointer (directed by a mouse or trackball) to select items on the desktop. These interfaces are sometimes called WIMP interfaces, after the first letters of the words window, icon, menu, and pointer. Here is a screen capture of a typical WIMP interface:


  .

The other user interface is a command shell. A command shell is simply a window without any graphical decorations. You type commands, using the keyboard, and you see the results of the commands displayed as text. There are no icons, and you can use the mouse only in limited circumstances. Here is a typical command shell:

.

A command shell is not a good user interface for casual users. However, experienced users find that the command shell is indispensible for many tasks.

Look at it this way. If you just want to snap vacation photos, you'll use a "point and shoot" camera. It requires no training and takes decent pictures.

.

But if you want your photos to be published in a magazine, you will need a professional camera. You will need to spend time learning rather technical concepts such as f-stops and shutter speeds.

.

We don't want to leave you with the impression that the command shell is the best tool for every job. Sometimes, you are better off using the GUI, particularly if you spend some effort learning how to use it efficiently. Just like a professional photographer chooses the best instrument for the job, you will need to learn when to use the GUI and when to use the command shell.

In this tutorial, you will learn some tricks that make the GUI faster and more efficient, and you will learn the basics of the command shell.

Keyboard Shortcuts

Running a program

After you log on to your computer, you see a desktop, which may or may not contain some icons (small pictures representing programs, services, or resources). At the bottom left of the screen is the Start button. Across the bottom, is the task bar which contains buttons for all currently running programs. If you are reading this document in a web browser (and not from a printout), then there should be a button corresponding to the browser program.  At the bottom right of the screen is a clock, possibly together with somesmaller icons.

You probably know how to launch programs by clicking on the start button or on desktop icons. We will now introduce another method.

Type the keyboard shortcut Ctrl+Esc. That is, hold down the Ctrl key, and, without lifting your finger off it, hold down the Esc key. Then let go of both keys (in either order). This keyboard shortcut simulates a click on the Start button.

Why use a keyboard shortcut? It is much faster to hit Ctrl+Esc than it is to

  1. grab the mouse
  2. move the mouse to the lower left corner of the screen
  3. click the mouse button

For a programmer, the first step ("grab the mouse") is the most painful. Programmers need to type a lot of code and therefore have their hands on the keyboard most of the time. In this regard, programmers are very different from casual computer users who have a hand on the mouse much of the time.

You will see a popup menu, containing icons and names. The exact layout of the menu depends on the version of Windows and on the customization of the start menu. Here is one example. Your dialog may well be quite different.

.

{short description of image} NOTE: If you use Windows XP, it is a good idea to switch the start menu to "Classic" mode.  The setting is inside the Taskbar and Start Menu control panel. (While you are at it, you should switch the control panel view to "Classic" mode as well.)

In any menu, you can quickly select items that have underlined letters in their names. For example, typing  R is the same as selecting theRun  item. Typing H is the same as selecting the Help item.

{short description of image} NOTE: If you use Windows XP, the underlined letters may not show up until you hit the Alt button. This unfortunate behavior can be corrected in the Display Properties control panel dialog. Select the Appearance tab and click on the Effects button...

Hit the R key now. You will get a dialog. Type the word notepad.

In most dialog boxes, hitting the Enter key is the same as clicking the Ok button. Typing Esc dismisses the dialog, just as if you had clicked the Cancel button.

Hit the Enter key now. The Notepad program launches.

Exercise 1
Which keystrokes are required to launch the Notepad program without touching the mouse?

Exercise 2
What is the advantage of using the Run dialog to launch the Notepad program? Hint: Locate the Notepad program in the start menu tree. In which submenu did you find it? How long did it take you to find it? Will it be in the same position on your friend's computer?

Toggling between programs

The next step of this tutorial assumes that you currently have a web browser running. If you are reading these instructions from a printout, go ahead and start a browser. Close any windows except for the browser and the notepad window.

You now have two windows on your desktop: the browser and the Notepad program. This is an extremely common situation for a programmer. You will often write a program in one window while consulting documentation in another window. It is essential that you can switch quickly between the windows, even if some windows hide others.

The fastest way of switching between windows is the Alt+Tab keyboard shortcut. Press Alt+Tab now. You will get a dialog that lists all windows. Release both keys. You instantly switch to the next window.

Start the calc program (Ctrl+Esc R calc Enter). You should now have three programs running. Hit Alt+Tab again, but this time keep the Alt key depressed and repeatedly hit the Tab key. You toggle through the program icons. Let go of both keys when you have reached the browser program.

Exercise 3
Run three programs, for example, a browser, the notepad, and the calc program. Switch to the browser program if it is not currently active (either with the mouse or with Alt+Tab).  Hit Alt+Tab and let go immediately. Which program is selected now? Hit Alt+Tab again and let go immediately. Which program is selected now? Why is the result surprising? Why is it useful?

Managing windows

When the time has come to close an unwanted window, you can close it by clicking on the X icon in the top right corner, or you can use a keyboard shortcut. There are actually two shortcuts. The combination Alt+F4 closes the active window, but even keyboard enthusiasts will find it hard to remember.

More useful is the Alt+Space shortcut. It brings up the window menu:

  .

Select C to close the window.

The window menu has a number of other useful options:
  • Maximize: Make the window fill the entire desktop
  • Restore: Restore the window to its original size, before maximizing
  • Minimize: Temporarily remove the window from the screen  (to reduce clutter)
You can get a minimized window back onto the desktop by cycling to it with Alt+Tab.

Exercise 4
Suppose you want to see as much information as possible in your browser window. What keystrokes do you use to maximize the browser window?

Cut, Copy and Paste

One of the most common operations for text manipulation is cut-and-paste: transferring information from one place to another. Because these operations are so common, there are special keyboard shortcuts for them.

Switch to the notepad window.

Pull down the Edit menu by typing Alt+E. Note the underlined E in the menu name. You pull down a menu by typing the Alt key and the underlined letter.


.

The Edit menu has commands for the Cut, Copy, and Paste operations. Thus, a perfectly reasonable keyboard shortcut for copying text would be Alt+E C. However, because the copy operation is so common, there is an accelerator, Ctrl+C, that lets you access the operation with a single key combination. You can see the accelerator listed in the menu. Similarly, there are accelerators for cut (Ctrl-X) and paste (Ctrl-V). These key combinations are perhaps not as easy to remember. You may find it helpful to visualize the X as crossing out text, and the V as an insert mark for adding text:


.

Also note that the letters X, C, V are located next to each other, conveniently close to the Ctrl key (at least, on the standard English QWERTY keyboard layout).


Exercise 5
Now switch to the browser window. If it doesn't currently show a document, then visit your favorite web site. Use the mouse to select a phrase of your choice. Your task is to copy the selected text to the Notepad program, without further use of the mouse. What keystrokes to you use?

{short description of image} NOTE: Many programs also support alternate keyboard shortcuts: Shift+Delete for cut, Ctrl-Insert for copy, and Shift-Insert for paste. However, these shortcuts are not as universally supported as Ctrl-X, Ctrl-C, Ctrl-V.

Moving the Cursor and Selecting Text

You can move the cursor by clicking on the desired location, and you should do that if the desired location is far from the current location. However, if you just need to move the cursor by a small amount, it is often faster to use the following keys:
  • The arrow keys Left, Right, Up, Down move the cursor one position
  • Ctrl+Left, Ctrl+Right move the cursor one word to the left or right
  • Home, End (above the arrow keys) move the cursor to the beginning or end of the line
  • PageUp, PageDown (above the arrow keys) scroll the page up or down. This is often faster than using the scroll bars.
.
You know that you can select text with the mouse, by clicking on the beginning of the text and dragging the mouse to the end. Indeed, that is often the fastest method. However, if you need to select a short amount of text and your fingers are on the keyboard, then it is useful to know a shortcut.

Hold down the Shift key and move the arrow keys. You will see that a portion of text is selected. You can also use keys such as Home and End to extend the selection to the beginning and the end of a line.

Exercise 6
Switch to the notepad. It should still contain some text from a preceding exercise. If not, paste or type a couple of lines. Now highlight the entire line containing the cursor, using as few keystrokes as possible. What keystrokes to you use?

Navigating in Dialogs

It is handy to know how to move quickly through the fields of a dialog box without using the mouse.

In any dialog box, you can use the Tab key to cycle through all of the fields and buttons. Consider for example the following dialog from the Notepad program. (The menu option is Edit -> Replace.)

.
{short description of image} NOTE: This is the dialog from Windows XP. If you use an older version of Windows, use the Search -> Find dialog instead. It isn't as interesting, but you can still use it to try out the Tab key behavior.

Type the Find what entry, then hit the Tab key to quickly get to the Replace with field. The Tab key is particularly handy for dialogs that have many text fields.

When you use the Tab key to cycle through the dialog box, observe how the focus shifts from one field to the next. A text field with focus has a blinking cursor. A button with focus has a dotted rectangle around the button label. The focus tells you which part of the dialog box receives keyboard input. For example, if a button or checkbox has focus, then hitting the Space bar is the same as clicking it with the mouse.

If an item name has an underlined letter (such as Match case), then you can type Alt together with the underlined letter to reach it quickly. For example, Alt+C is the same as clicking the Match case checkbox.

Finally, most dialogs respond to two special keys. Typing Esc dismisses the dialog, just as if you had clicked the Cancel button. Typing Enter is the same as clicking the Ok button.

Exercise 7
Open up the Find dialog in Notepad. What keystrokes do you need to find the next occurrence of Hello, with Match case checked? Keystrokes only, no mouse!

You know know the most common keyboard shortcuts. After a short amount of practice, you will probably agree that the keyboard is mightier than the mouse for many routine tasks.

The File System

Disk drives

Disk drives for computers come in two main types, removable (floppy, CD ROM) and non removable (hard). Whether hard or floppy, a computer disk drive essentially contains a round, flat, object, and it reads its surface with a magnetic or optical head.

In addition to the disk drives that are physically present in a computer, there may be several mapped drives that are provided by the network server. These are not actual drives at all, but look to the operating system (and to you) as though they are.

The drives that hold the disks are named by a letter followed by a colon (:). The names a: (and perhaps b:) are the floppy drives. The names c: and d: are usually used to name hard disk drives in that same computer. CD ROMS come next, labeled e: (or d: if there is only one hard disk). Higher letters like j:, k:, ... are mapped network drives.

{short description of image} NOTE: Sometimes, a single hard drive has multiple partitions. Even though there is only a single physical drive, it divided into several areas, each of which has its own drive letter (c:, d:, ...). If you set up your own computer, it is an excellent idea to set up two partitions, one for the operating system (c:) and one for your personal data (d:). That setup enables you to reinstall the operating system without interfering with your personal data. (Unfortunately, the Windows operating system is notorious for becoming unreliable over time, as more software is installed and programs and drivers interfere with each other. The best remedy is to periodically wipe the c: partition clean and reinstall Windows.)

.
NOTE: In Linux/Unix/Mac OS X, there are no drive letters. Instead, CD ROM and floppy drives are accessed through paths such as /mnt/cdrom and /mnt/floppy.


There are many ways to find drives and view their contents using Windows. The program we will use is called Windows Explorer. (This is not the same program as Internet Explorer, Microsoft's web browser. The Windows Explorer program explores the file system, not the internet.)

To start the Explorer program, open the Run dialog (Ctrl+Esc, R) and type explorer followed by the Enter key.

.

The look of the Explorer has changed greatly with different versions of Windows, and it can also be configured in many ways. Don't worry if your Explorer window looks quite different from this screen shot.


Exercise 8
List all available drives with their names and drive letters. (You may need to open the My Computer item.)


Each drive contains files and directories (also called folders). In the Explorer program, click on a drive to see the files and folders. The files are depicted with an icon that looks like a file folder. Files have different icons that depend on their type.

.

Exercise 9
List all files and directories that are inside your c: drive. (Don't look inside the directories.)

Directory Trees

A typical hard disk holds thousands of files. It is therefore essential to organize your files on the disk. As you accumulate files on a disk, you  store them in groups by creating directories. Directories are also called file folders. Generally, programmers prefer the term "directory", and we will use that term in this tutorial.

Each directory can contain any number of files and other directories called subdirectories. This arrangement is known as a hierarchical or treelike directory structure.

To visualize the hierarchy of directories, it is best to look at the tree view to the left of the Explorer window.  Note that each drive has a small box next to it with either a + or - sign in it. This indicates whether the next level of the directory hierarchy is hidden or expanded. Click on the + icon to expand a hidden level, on the - icon to hide an expanded level.

On each drive, the hierachy starts with the root directory. The name of the root directory is simply the drive name followed by a backslash (such as c:\). The root directory contains files (such as c:\logfile.txt) and directories (such as c:\windows). The windows directory contains other files (such as c:\windows\notepad.exe) and directories (such as c:\windows\system).

The sequence of subdirectories from the root to a given file or directory is called the path. For example, c:\windows\system is the full path name of the system directory inside the windows directory inside the c: drive.

Exercise 10
List an additional file and an additional directory in the c:\windows directory. List a file and a directory in the c:\windows\system32 directory.  Give the full path names for the files and directories.

Exercise 11
Find the files explorer.exe and telnet.exe. Give the full path names. (Hint: You may find it easier to look for files if you select the list view rather than the icon view for directories. Choose the View -> List menu option.)

Exercise 12
Find a file whose full path names contains at least four directories.
.
NOTE: In Linux/Unix/Mac OS X, directories are separated by forward slashes (/). For example, /usr/local/java/bin. That is the same convention as for web page addresses. Only Windows uses backslashes (\).

Making Directories

For this part of the tutorial, you need to find a directory into which you are allowed to place files and folders. On your own computer, you can simply use c:\, the root directory of the c: drive. If you work in a computer lab, you will need to find out the name of the directory that was created for your use.


View your directory in the Explorer program. Select File -> New -> Folder (Alt+F W F). This command places a folder icon inside the directory and gives it the temporary name New Folder. It also leaves the cursor in the name field, allowing you to change it immediately. Hit Delete to erase the name, and give it a new name. A good choice for a name is your own name, contracted to a single word without spaces (such as joe or jqsmith).


If you use your own computer, create this directory now. From now on, place all files in this directory. If you use a computer in a lab and someone else has already given you a directory with your name (perhaps d:\jqsmith or c:\users\jqsmith), then you can skip this step.


We will refer to "your" directory as the c:\yourname directory in this tutorial, even though it will certainly be something else (unless, of course, your name is Yolanda O. Urname...)


Exercise 13
Create a subdirectory called tutorial inside the c:\yourname directory. (Substitute the actual directory that you created.) List all steps, starting with launching the Explorer program. (Close it first if it is currently running).

File and Directory Names

You can use letters, numbers, the underscore (_) and the hyphen (-) character in file names. Obviously, you can't use symbols such as : and \ in file names, or they would be confused with drive and directory separators. There are a few other special characters that you can use, but the details depend on whether the drive is a local drive or a networked drive. It is best to avoid file names with exotic symbols such as !@#$.


You can use spaces in file names, but programmers rarely do that, because spaces in file names create problems when you use a command shell. Instead, use - or _ to separate words: myproject-ver0.01.java or letter_to_fifi.txt.


Both uppercase and lowercase letters are permitted in file and directory names, but Windows will not distinguish between names that differ only in the case of the letters.


Exercise 14
Create another subdirectory called TUTORIAL inside the c:\yourname directory. (Substitute the actual directory that you created.) What error message does Windows give you? What does it do after you click OK?

Files

Start the Notepad program: Ctrl+Esc R notepad Enter. Type a few words. Select File -> Save As from the menu. You will get the Windows file dialog.

.

The dialog suggests a file name *.txt. However, you can't actually use the * character in a filename. Also, the current directory is likely to be wrong. Fortunately, in most versions of Windows, the useless default is also highlighted, so you can overtype it.

Simply type c:\yourname\. (Actually, type the name of your personal directory.) Type the letters s l o w l y and pay close attention to the entry field. You will see that a small menu below the entry field is filled with the names that match what you have typed at this point.

.

This feature is a great time-saver. As soon as you see the name that matches what you want to type, hit the Down arrow button to select it. Presenting all choices that match the typed letters is called incremental search. Clearly, incremental search is a marvelous convenience because it minimizes the number of keystrokes.

Exercise 15
What choices do you get after you type the letter c (or whatever the drive letter of your personal directory is)? What choices do you get after you type c:\ and the first letter of the directory name? 


{short description of image} NOTE: Very old versions of Windows do not offer incremental search in the file dialog.

Save the file as c:\yourname\tutorial\sample.txt. Be sure to supply the extension .txt. That extension signifies that the file is a text document.

Exercise 16
Close the Notepad program and locate the file that you just saved in the Explorer program. What icon does it have? What name is displayed for the file? What happens when you double-click on the file name?

Depending on the configuration of Windows, the extension .txt may not be displayed when you view the file in the Explorer program. By default, Windows hides the extensions, presumably because naive users are confused about file names such as letter to aunt tilly.txt.

{short description of image} NOTE: Hiding extensions is primarily helpful for virus writers. Many Windows users have eagerly double-clicked on icons labeled something like prettygirl.gif, only to launch a virus program whose real name was prettygirl.gif.exe.

As a programmer, you don't want the operating system to hide information from you. Fire up the Explorer program and select Tools -> Folder Options and select the View tab.

.

M
ake sure the check box next to "Hide file extensions for known file types" is unchecked. Click on it if it is checked.  Then hit Enter or click OK. Make sure to repeat this step on every Windows computer that you use.

Windows uses the file extension to figure out what to do with the file when you double-click on it. Double-clicking on a .txt file brings up Notepad. Double-clicking on a program file (with extension .exe) executes the program.

You can find out which program corresponds to a particular extension. In the Explorer program, select the Tools -> Folder Options File Types tab. You get a list of all file types that are registered with Windows. You (or a program that you install) can modify these associations.

Exercise 17
Which program is associated with the extension .html? Which program is associated with the extension .gif?

Context Menus

Items such as file and directory icons in the Explorer display have context menus that contains commands directly related to the item. This menu can be displayed by clicking on the object's icon with the right mouse button.

.

One of the most useful entries in the context menu of a file is Rename. To rename a file, right-click on the file, select Rename and type the new file name. 

Exercise 18
What are the commands listed in the context menu for the c: drive? What are the commands listed in the context menu for the c:\yourname\tutorial\sample.txt file?

Moving and Copying Files

Files and directories often need to be copied. There are two methods for copying files with the Explorer program.

The most intuitive method is drag-and-drop: select a file with the mouse, drag it to another directory, and drop it. If you hold down the Ctrl key while dragging the file, it is copied, not moved.

With some manual dexterity, you can also drag a group of files. To select more than one file, depress the Ctrl button and click on all files in the group. For selecting multiple files with similar properties (such as the same extension, or similar modification dates), you may find it helpful to switch to a tabular view (menu option View -> Detail). Depress the Shift button and use the Up and Down arrow keys to select a contiguous set of files.

The difficulty with drag-and-drop is that both the source and target directory need to be on the desktop. You can overcome that problem by cutting and pasting files. Select the files you want to move or copy. Then select Edit -> Cut (or simply Ctrl+X), move to the directory into which you want to move the files, and select Edit -> Paste (Ctrl+V). To copy the files, use Edit -> Copy instead.


Exercise 19
Copy all files with extension .txt from the c:\yourname\tutorial directory into the c:\yourname directory. What sequence of keystrokes and mouse operations did you use? (Make sure to copy the files. Do not move them!)

Backing up your work

Computers are fairly reliable, but their parts do have a finite lifetime. Also, important files can sometimes be destroyed by careless computer users. You should make it a habit to back up all important files. Your instructor will likely not accept "The computer ate my file!" as an excuse for late or missing homework.

In ancient times, floppy disks were used to back up data. However, floppy disks are actually more fragile than hard disks. Also, the disk drive alignments of different computers can vary, sometimes so much so that it becomes impossible to read a floppy disk that was written on another computer. It is best if you use floppy disks as a matter of last resort.

On your own computer, the most convenient backup method (as of 2003) is a CD burner. Windows XP has a rudimentary feature set for burning CDs. You can insert a blank CD, drag files onto it, and burn the CD. However, some computer manufacturers preload software that offers a different interface to the CD burner, and older versions of Windows require a separate programs for CD burning. Since the details vary widely, we cannot review the process in this tutorial.

The best method for backing up your work in a computer lab is an online service such as Yahoo Briefcase. You can save files on an external server and load them back either onto the same computer (in case you need to restore a lost or corrupted file), or onto another computer (in case you need to move your work between your lab and home computers).

Exercise 20
Back up the file c:\yourname\tutorial\sample.txt, either onto an online service or onto a floppy.  Describe the steps that you took. Now delete the file and restore it from your backup. What steps did you take to restore the file?


The Command Shell

You have now learned how to navigate the Windows desktop effectively. The final part of this tutorial covers the command shell. You may wonder why you need to learn another method for achieving the same tasks. There are three reaons:

  1. It is much faster to type certain commands than clicking and dragging with the mouse. For example, suppose you want to erase all text files in a folder. In a GUI, you select all text files and then drag them to a trash can icon.  In a command shell, you type a few keystrokes such as
    del *.txt
  2. You can save the output of a command for later processing. For example, suppose you want to do something with all text files in a folder. You can save their names in another file with a command such as
    dir *.txt > names.dat<br>
     Try doing that in a GUI. If you take a screen capture of a folder display, all you get is a bunch of pixels.
  3. You can automate repetitive commands. For example, suppose you have multiple text files and want to compress each of them into a separate file. You can use a loop such as
    for %f in (*.txt) do jar cvf %f.zip %f<br>
    If there are many files to process, such an operation would be very tedious with a GUI. Many worthwhile tasks are never attempted by GUI users just because they don't know how to automate them.

Starting the Command Shell

Open the Run menu and type cmd (or command if you use a version of Windows prior to XP): Ctrl+Esc R cmd Enter. The command shell window appears:

.

The command shell has a rather primitive user interface.

  • A prompt shows the current directory, such as c:\windows.
  • You type a command and hit the Enter key.
  • The command is executed. Its output is displayed in the shell window.
  • Another prompt is then displayed, and the process repeats until you close the shell window.
Exercise 21
What prompt is displayed when you open up a command shell window?

Type the command

dir<br>

followed by the Enter key into the shell window. You will see a listing of the files and directories in the current directory.


Exercise 22
How many files are contained in the current directory? How many directories?

Now type the command

cd \<br>

Don't forget hitting Enter.

Exercise 23
What does the prompt string look like now?

Exercise 24
What files and directories are contained in the root directory?

Now type

cd \yourname<br>

As always, replace yourname with your personal directory name. If your directory is contained in a drive other than C:, you first need to switch to the other drive by typing the drive letter followed by Enter, for example

j:<br>cd \users\jqsmith<br>

Next, type

cd tutorial<br>
Exercise 25
What does the prompt string look like now?

Type

cd ..<br>
Exercise 26
What does the prompt string look like now?

Finally, type

cd \tutorial<br>
Exercise 27
What happens? Explain.

You have just learned the basic directory commands in the shell:

Typing cd plus a path changes the directory to the given path. Here a path can be relative to the current directory or absolute. Absolute paths always start with the root directory (\). Relative paths begin with a file name in the current directory.

There is one special file name that is very useful: the double period (..) refers to the parent directory of the current directory in the directory tree, so that it is possible to go up the tree with relative paths as well as down. Similarly, the filename. refers to the current directory, but that abbreviation is not commonly needed.

Typing dir lists files in the current directory. You can also give dir a relative or absolute path, and it will display the appropriate directory, such as

dir ..\projects<br><br>

Command Line Editing

Some people dislike using the command shell because it is tedious to reissue commands that were mistyped. Fortunately, it is possible to retrieve and modify previously issued commands.

Hitting the Up and Down arrow keys cycles through the commands that you already typed.


Exercise 28
What command do you see when you hit the Up arrow key? What command do you see when you hit the Up arrow key again?

{short description of image} NOTE: If the arrow keys don't retrieve old commands and you run Windows XP, double-check that you are running cmd and not the older command shell. If you have an older version of Windows, you need to run the doskey program to enable command line editing. Simply run doskey after you open a command shell.


Exercise 29
Type c and the F8 key. Hit F8 repeatedly. What happens?

The F8 key performs a search of the previous commands that start with the text you have already typed. This is often the fastest method for retrieving an old command.

You can use the cursor keys (Left,Right, Home, End) to edit the line that you called back. Move the cursor where you want it and insert or remove characters. If inserting characters types over existing text, hit the Ins key to switch from overtype mode to insert mode.

Exercise 30
Type cd \windos (note the misspelling). After you get an error message, use command-line editing to fix it to cd \windows. What are the key strokes that you used?

Another very useful feature of the shell is filename completion. If you type a part of a filename and hit the Tab key, then the first matching file is displayed. Hitting Tab again cycles through all matching completions.

Exercise 31
Type cd c:\w and hit Tab. What happens?
{short description of image} NOTE: Filename completion only works with Windows XP. It does not work with older versions of Windows.

Finally, if you look for a command and you don't find what you want, you can clear the command line and start over by hitting Ctrl+C. Indeed, this command can be used to stop almost any action that is still in progress.

File Commands

The del command deletes a file. For example,

del sample.txt<br>

deletes the file sample.txt.

{short description of image} NOTE:When you delete a file with the del command, it does not get moved into the trash can. It is deleted for good and cannot be retrieved. 

To copy a file, use the copy command, followed by the target file or directory. For example,

copy sample.txt sample.bak<br>

copies the file sample.txt and names the copy sample.bak.

Exercise 32
How would you achieve the same effect using the Explorer program?
copy sample.txt a:\<br>

copies the file sample.txt into the directory a:\. Because the target of the copy command is a directory, the copied file keeps the same name.

To move a file, use the move command. For example,

move sample.txt a:\<br>

moves the file sample.txt to the directory a:\, removing the original.

You can also use the move command to rename a file. The command

move sample.txt sample.bak<br>

renames the file sample.txt to sample.bak.

Exercise 33
How would you achieve the same effect using the copy and del commands?

Directory Commands

The mkdir command makes a directory. For example,

mkdir \yourname\homework1<br>cd \yourname\homework1<br>mkdir backup<br>
Exercise 34
Execute these commands. What is the full path name of the backup directory that was created?

You remove a directory with the rmdir command. However, in order to be removable, a directory must be completely empty. That is, you must first remove all files and directories that it contains.

Exercise 35
Execute thes command
rmdir \yourname\homework1<br>
What error message do you get? How can you remove the directory?

Wildcards


Often when we want to copy files, we only want files of a certain type (that is, with a certain file extension). For example, we may want to copy only text files (with extension .txt). We use the wildcard notation for this purpose.

The command

copy *.txt a:\<br>

copies all files whose names end with .txt to the a:\ directory.

Exercise 36
How would you copy all text files from the c:\windows directory to c:\yourname? Why is this a better solution than the one you found in exercise 19?
Exercise 37
What does the command
del c:\yourname\*.*<br>
do?

The asterisk (*) in the entry *.txt stands for any sequence of characters of any length. (Note how the file extension is given separately.) The other wildcard that is available is ?, which stands for any single character. Here are two more examples of the use of these wildcards:

The string s*.txt matches all files beginning with the letter s and having the extension txt.

The string st??.ba? matches all files beginning with the letters st whose filenames have four characters, and whose extensions consist of three characters beginning with ba.


Exercise 38
Use the dir command and wildcards to find all files in c:\windows that start with a w, have three letters, and whose extension is ini. What command did you issue, and what matches do you get?

Command-Line Options

Many shell commands take options that modify their behavior.

For example, the dir command has an option /w that produces a "wide" listing, with several files in each line. The command is

dir /w<br>

for a wide listing of the current directory, or

dir /w c:\windows<br>

for a wide listing of the Windows directory.

Another useful option of the dir command is /p.

Exercise 39
Try the command dir c:\windows /p. What is the effect of the /p option?

You can combine multiple options:

dir /w /p c:\windows<br>

In general, an option to a command starts with a forward slash, followed by a letter. Note that forward slashes (/) are entirely different from from backslashes (\), which are path separators. Most commands have several options, which you can find in the online help.

You can also get a brief description of a command and its options through the /? option, for example

del /?<br>
Exercise 40
What are all options of the del command?
.
NOTE: In Linux/Unix/Mac OS X, you use a dash, not a forward slash, for options. For example, ls -a.

Copying from and to the Shell Window

Sometimes, you need to copy information from a command shell window into another window (for example, to include output in a report or email). Unfortunately, this process is somewhat cumbersone.

  • Right-click on the command shell window. A context menu pops up.
  • Select the Mark option.
  • Use the mouse to select a rectangular area. (You can also use the cursor keys. Hit Down to move to the first line that you want to copy, then press Shift+Down to select the lines you want to copy.) 
  • Hit Enter
  • Switch to another program (such as Notepad) and paste (Ctrl+V).

Obviously, this method can only be used to copy a single screen to Notepad or another application. To get more than one screen, you will need to use redirection, which is described in the advanced lab.

Conversely, you may want to copy a command from another program (such as a web browser) into the shell window. Copy the command, then right-click on the shell window and select the Paste option.

Exercise 41
Copy this command
dir /oen /p c:\windows<br>
into the shell window and execute it. What happens?

Executing Programs

To execute a program from the command shell, you type the program name. For example, to launch the Explorer program, type

explorer<br>

You can also provide command-line arguments. For example, to launch the notepad program and edit a particular file, simply specify the file name.

notepad c:\yourname\tutorial\sample.txt<br>
Exercise 42
Execute the command
notepad c:\yourname\tutorial\myfile.txt<br>
What happens? Explain.

When you give the name of a command, then Windows tries to find an program file with that name. For example, when you type notepad, then Windows looks for the file notepad.exe. It looks for the program file in the current directory, then in a set of standard places that include the c:\windows and c:\windows\system32 directories. If the program file is not found, then an error message is displayed.

Exercise 43
Execute the command
notpad <br>
(Note the misspelling). What happens? Explain.

Sometimes, you need to execute a file that is not a part of the "standard places". For example, if you install the Java compiler, it is installed into a directory such as c:\j2sdk\bin. By default, Windows will not look inside that directory. You can, however, launch the program by giving the full path name

c:\j2sdk\bin\javac MyProg.java<br>

You will see a better solution in the advanced lab.

Exiting the shell

To close the shell window, type the command

exit<br>

Alternatively, simply close the shell window.

Exercise 44
Execute the command
exit<br>
What happens?


Read More ..