|
Sometimes referred to as a command script,
a command language is a language used for executing a series of commands
that would otherwise be executed at the prompt. A good example of a command language
are Microsoft Windows batch files. Although
command languages are great for performing a series of commands or
commonly performed series of commands that would be run at the command
prompt, some command
languages can be limited when compared to other programming
languages and scripting languages because they often only allow little
more than what is available at the command prompt. However, this
language is often much easier to use and run because they often are
no more than
a series of the same commands run at the command prompt
and do not require the files to be compiled.
Below
is a basic example of a Microsoft Windows batch file that deletes
all the files in the Windows temp directory.
|
REM
Delete Windows temp files. echo Deleting Windows temp files. cd\window\temp del *.* /q |
Below
is a basic example of a Perl script that
could be run in Microsoft Windows that performs a similar task to
the above batch file example but with some more sophistication.
|
#
Delete Windows files and log results into log.txt
my (@files, $files);
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst, $timeoffset);
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime;
$year = $year + 1900;
@files = `dir /b c:\windows\temp`;
open(mylog, ">>log.txt") || print "ERROR: $!";
foreach $files (@files) {
$files =~ s/\n//g;
system("del c\:\\windows\\temp\\$files /q");
print "Deleting $files at $hour:$min:$sec on $mon/$mday/$year\n";
print mylog "Deleting $files at $hour:$min:$sec on $mon/$mday/$year\n";
}
close(mylog); |
Note:
It is possible to do what we have done in Perl in a batch file, we
are just using this as an example. We would also like to mention
that the above Perl script is just a quick example and could easily
be expanded to do almost anything imaginable. Finally, because this
is just a quick script for Microsoft Windows, we are using system
commands that would make the script difficult to port
over to another operating system such as Linux.
Of course the script could be modified to work with any operating
system and/or Perl modules could be
used to make this script more efficient.
Advantages of command languages:
- Very easy for all types users to write.
- Do not require the files to be compiled.
- Easy to modify and make additions to.
- Commonly very small files.
- Do not require any additional programs or files that are not
already found on the operating system.
Disadvantages of command languages:
- Can be limited when comparing with other programming languages
or scripting languages.
- May not execute as fast as other languages or compiled
programs.
- Some command languages often offer little more than using the
commands available for the operating system used .
In conclusion, scripts and command languages are very similar;
however, scripts or programs offer the user the ability to perform
much more than just commands that would otherwise be executed at the
prompt.
- Additional help and
information with batch files can be found on our
batch
page.
Also see: Command,
Language, Programming
definitions, Script
|
|
| Resolved | Were you able to locate the answer to your questions? |
|
|