Win32 Shell Scripting Tutorial

ADVERTISEMENT


Win32 Shell Scripting Tutorial cover page
Introduction to Win32 Shell Scripting … due to reasons unknown, many useful tools for batch programming have been omitted in recent versions of Windows … Win32 ShellScripting Tutorial AshleyJ.SMills< ashley@ashleymills.com > Copyright©2005 The University Of Birmingham Table of Contents 1. Introduction to Win32 Shell Scripting ….. 1 2. The Environment…..

1. Introduction to Win32 Shell Scripting Time is precious. It is non-sense-icaltowastetime typinga frequently used sequence of commands at a command prompt, more especially if they are abnormally long or complex. Scripting is away by which one can alleviate this necessity by automating these command sequences in order to make ones life at the shell easier and more productive. Scripting is all about making the computer, the tool do the work. Hopefully by the end of this tutorial you should have a good idea of the kinds of scripting languages available for Windows and how to apply them to your problems… . Batch Programming A batch file is a plain ASCII text file with the file extension .bat , it is interpreted by the command processor, usually command.com or cmd.exe . Batch files are used to automate repetitive command sequences in the command shell environment. In the context of batch programming, the environment is exploited for it’sabilitytostore text strings within definable variables known as environment variables as illustrated in the above example, these variables can be used in batch files in much the same way as you would use variables in other programming languages albeit with less freedom. The language used in batch files is usually referred to asascripting language but it is in-fact Turing-complete hence is actuallya programming language. 3.1. Auxiliary files for extended batch programming Unfortunately, due to reasons unknown, many useful tools for batch programming have been omitted in recent versions of Windows and are only available from within costly’resource kits’that one has to purchase for seemingly extortionate sums of money. However, there are free alternatives to some of these tools and/or hacks/kludges to circumvent their necessity. 3.1.1. OldDos.exe ftp://ftp.micros oft.com/softlib/mslfiles/olddos. exe This is a self-extracting archive containing some of the files that were distributed with versions of Windows prior-to and including Windows 95, programs such as qbasic . 3.1.2. NTResourceKit http://www.micro soft.com/ntserver/nts/downloads/recommended/ntkit/default.asp This is a subset of the tools found in the full Windows NT Resource Kit. Only available for Windows 2000/NT/XP users. 3.1.3. CHOICE.EXE CHOICE.EXE is a batch command which allows the requisition of a choice from a basic set of choices presented to the user. 3.2. Batch Basics 3.2.1. Command Redirection and Pipelines If you want to get help on a command in Windows, the usual way is to postfix the command with a space and then /? . By default a normal command accepts input from standard input, which we abbreviate tostdin, standard input is the command line in the form of arguments passed to the command. By default a normal command directs its output to standard output, which we abbreviate tostdout, standard output is usually the console display. For some commands this maybe the desired action but other times we may wish to get our input fora command from somewhere other thanstdinand direct our output to somewhere other than stdout. This is done by redirection: •We use > to redirect stdouttoa file, for instance, if we wanted to redirect a directory listing generated by the ls we could do the following: ls > file •We use < to specify that we want the command immediately before the redirection symbol to get its input from the source specified immediately after the symbol, for instance, we could redirect the input to grep (which searches for strings within files) so that it comes fromafilelike this: grep searchterm < file •We use >> to append stdouttoa file, for instance, if we wanted to append the current directory listing to the end of a file we could redirect the output from dir like so: dir>> file

Download Win32 Shell Scripting Tutorial.Pdf

Personalize Your Document Now

Leave a Reply