Command Prompt

From UFOpaedia
Revision as of 03:41, 13 April 2009 by NKF (talk | contribs) (Extra Stuff: Crossed off a few to-do's)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Back in the day, computers didn't have all these fancy mouse-pointer and icon things. No, they used DOS. (Well, actually, they used punch cards, and you could make 'em go faster by turning the handle on the side, but for now we'll say DOS).

UFO was originally designed to run under MS DOS (that is to say, Microsoft's version of DOS - Microsoft didn't introduce DOS itself). Now, with the the introduction of the Windows based CE version it's not so necessary to know how to use this ancient UI - But nevertheless there are times when it's just more practical to do things via a command prompt.

Booting To DOS

If you have a 9x based system (for example, Windows 95, 98, or ME), your computer is capable of booting to the final version of DOS. Note that although Windows ME does have the functionality, it's been hidden - you'll need to install a small patch to enable this feature.

Note to self - Hunt that patch down! It's on my harddrive... Somewhere...

There are two ways you can do this. When your system is booting, as soon as you see the message telling you that Windows is starting, tap your F8 button. You'll get a menu of boot choices, and amongst them will be the command prompt.

If you miss your chance to hit F8, you can still tell your machine to boot to DOS by selecting Start, Shut Down, and then using the Restart in MS-DOS option.

Your screen will turn black, with a small white prompt in the top left corner. While in DOS mode, Windows programs cannot be used, memory management is performed manually (which, whilst making things a bit complex, allows you to run some stuff that won't work under Windows) and file access is a lot, lot slower.

NT based systems do not have access to Real DOS - However, as of XP's improved DOS VM, they don't really need it.

If your computer has been configured to first boot from the floppy drive before booting from the hard drive, you can boot to pure dos by way of a boot disk. A boot disk is simply the minimum encessary operating system kernel along with the DOS user interface.

When you start your computer with such a disk, you will not have access to Windows or its other facilities.

Boot disks were originally in use to allow you to boot up your computer in alternate configurations. You could load up the CD-ROM and sound drivers with one boot disk, or you could use another boot disk and boot up your computer with the barest minimum settings. But this was mainly because computers in the old days were severely limited with what they could do. You often had to make your system as lean and mean as possible by dropping or adding different drivers and system settings to optimise your system in different ways.


Boot disks aren't a bad option if you have an older computer and are running one of the earlier incarnations of Windows, such as 95 and 98. However, todays computers have advanced so much since then, and particularly with more recent operating systems, you shouldn't need to use them for normal every day use.

The main disadvantage of a boot disk is that you are required to leave the boot disk in the floppy drive all the time and floppy drive read speeds tend to be very slow. Every time you go back to the command prompt, the computer will want to access the files on the boot disk. This can get tedious. Fast. And you were prevented from using the primary floppy drive.

If you're clever and point the COMSPEC parameter to the command.com or cmd.com on the hard drive you will remove the need for the operating system from accessing the floppy drive constantly. Don't worry if that last bit sounds like gibberish - this needn't be covered, but a mention of parameters may come in later in relation to the DIR command and its dircmd parameter for setting the default look of your directory listing.

Accessing The Microsoft DOS VM

Unless you're using a non-Microsoft OS, or your computer is really really old, chances are your computer loads up Windows when you turn it on.

Once Windows has loaded, click on your Start Menu, then select Run. If you're using a 9x based system (that is, Windows 95, 98, or ME), type "command" and press enter. You'll otherwise be using an NT based system (such as, Windows NT, 2000, or XP), in which case you'll need to use the term "cmd" instead.

The black window that'll appear on your screen is known as the Command Prompt. It looks a lot like DOS does, but it's a fake - any commands you run through this thing go via what's known as the DOS VM (Virtual Machine).

The DOS VM has improved over the years, and by now, it's nearly as capable as the original was. The pros are that memory management is done for you, most drivers are automatically made available, and you get the benefits of much, much faster file access (even under Windows '95). The cons are that the DOS VM can't emulate old hardware very well, so often you'll be forced to go without features such as sound. Many old DOS programs don't expect to be running on processors as fast as those used today anyway, and will fall over if you try it.

Note that the DOS VM also loads whenever you execute any DOS based program from Windows.

Using the DOS/Command Prompt Console

Using the console is just a matter of typing stuff in and pressing enter. To demonstrate this, let us start with the dir command.

Of the two command lines available in the dos console dir is the one you should ALL have access to. It's also the easiest to use as you don't have to manage your memory/drivers - the same is true for DosBox), so this tutorial will assume that is what you are using.

First off, you'll see a Windows copyright notice, and beneath it, a directory name with a flashing flashing line at the end of it.

The initial display

Load up explorer (Windows Explorer to be precise, though a web browser will work too), and type that directory name into the address bar. Hit enter to bring up the file display.

Windows Explorer

Back at the console: That flashing line is your cursor, and when you type stuff, that's where it'll appear. Type dir (which is short for "directory listing") and press enter.

Your first command

Up flashes the list of files, same as shown in Windows Explorer! Your listing may not be the same as in the above example, but the information is essentially the same - folders have the <DIR> tag beside them to differentiate them from files, which don't.

Note that I'm logged in as "Administrator" - This is not a good practice if you care about your systems security. But, because that's outside the scope of this article (and indeed, this entire Wiki), I only point it out because if you're logged in under some other user name, you'll see a different directory when you load the Command Prompt.

In fact, depending on your shortcut settings, you might not even end up in the "Documents and Settings" section of your drive at all - but that's nothing to be concerned about.

Parameters

In the above example of the "dir" command, not all the files and folders Explorer displays in my example turn up in the Command Prompt window. This is because those extra entries are hidden - explorer greys out their icons to show this (though some systemsmay be setup not to display them at all). Our "dir" command can also find them, but only if we tell it to!

Under Windows, to run a program, you double click it's icon. Using the command prompt, you type it's name, and it's name, and press enter. However, the command prompt allows you to type in extra pieces of information, which tell programs to run in certain ways. These are called parameters.

One parameter that is common to many programs, especially those built into your command prompt, is the "/?" command. The / symbol precedes most parameters, and the ? is the command itself - in case you can't guess, ? means "help".

Type dir /? and press enter.

Explanation of the dir command

Up comes a screen full of information, telling you all about the dir command, and what other parameters it can use. Anything listed between the [ and ] symbols is optional. Note the /A parameter - It's used along with attributes, which are basicly more parameters! In this case, we want to see hidden files, so it's the "H" attribute we want. Use the command dir /ah to see the hidden files.

Hidden file listing

Feel free to try out the other parameters of the dir command, as it's one of the commands that can't break your computer. dir /as, for example, will show you system files - dir /ash will show you files that are hidden as well as system files. dir /p is very helpful when you want to view a directory listing which is longer then your screen can display in one go.

It's a good idea to use to "/?" on any tool you're unsure about before running it. Certain commands can cause a lot of damage to your files if you don't know how to use them correctly.

Changing Directories

So by now you know how to use commands, find out more about them, and even how to change their behaviour. Yes, all that already! Sure, you only know one command, but it's a good start none the less.

The next command you need to know about is "cd" (which is short for "change directory"). Run it now (cd and then enter, if you haven't caught on yet). All that happens is that a copy of the directory you're currently in appears on the screen - not the contents, just the directory path.

Now run "cd" with the "/?" parameter (cd /? and then enter). Much of what comes up on the screen is most likely gibberish to you, but read through it anyway. You might learn something.

To do anything useful, "cd" requires parameters. Run the command cd .. - which, according to the command help, should change you to the parent directory. What you see next depends on where you were in your drive - if you started in "C:\Windows", for example, you'll go to "C:\", or if (like me) you started in the "C:\Documents and Settings\Administrator" folder, you should change to "C:\Documents and Settings".

If you run the dir command again (use the /p parameter if you need it), you'll see the directory you used to be in on the new listing (either "Windows" or your user name), along with all the other files and folders.

So, that's how we go backwards in our directory structure. But, what if we'd gone into lots and lots of subfolders, and we wanted to go all the way back, quickly? Well, the command cd \ sends you back to "C:\", no matter where you are. Unless you're on another drive, that is, in which case you'd go to "D:\", "A:\", or whatever was appropriate.

To change drives, you only need to type in the drive name. For example, d: (if you wanted to change to D:), a: (if you wanted to change to A:), and so forth. If you don't have a drive, or if a drive requires a disk to be inserted before you can change to it, you'll be told so and your position won't change.

Change back to the root of your C: by running the commands c: and then cd\. Note that the space between "cd" and it's parameter isn't required unless you're changing drives, or in another circumstance I'll get to later.

Where's your copy of UFO installed to? Let's change to that directory. In my case, I have a few copies littered about my drive, but the primary one is "C:\Games\X-Com I - UFO - Enemy Unknown (Gold)" That's a bit of a mouthful to type, so I can get there in stages.

The first command is cd\games - The first slash signifies the beginning of my drive, then the word "games" stands for the folder I want to enter.

Now I'm in the games folder, I want to change to the next one - "X-Com I - UFO - Enemy Unknown (Gold)". Since it has spaces in it, what's to stop the Command Prompt thinking I've typed in lots of parameters? Nothing, really, but I can get away with it if I type it in with quotes. The command cd "X-Com I - UFO - Enemy Unknown (Gold)" will get me there.

(Windows 9x users need to use quotes around any directory name that is longer then eight characters in length. I'll explain why later).

Note that I didn't use a slash. This is because I don't want to start moving from the beginning of my drive, I want to start moving from the folder I'm in. Hence, I could use the cd\games command to get to my games folder no matter where I already am, but if I want to enter a folder that is in my current folder I use a space, not a slash.

Note also that if you're using Windows 2000 or XP, your command prompt has an auto-complete option! If you type in a few letters of a folder name, then press your Tab key, the rest of the name will pop up (if there are multiple possibilities, keep pressing Tab to cycle through them). You can also use your up and down arrows to cycle through commands you've used. And yes, I know Linux users have had these for features years before Microsoft users got them, so you can all be quiet. :P

There are many other ways the cd command can be used. It's one of those "safe" commands, so feel free to experiment.

Examples of the CD command

Another alias for cd is chdir. It is the same command, it's just needs more typing.

Running Real Programs

So far we've used two commands - "dir" and "cd". These special commands are part of a set the your operating system lets you use no matter where you are in a drive.

Programs that you've installed to your computer are activated the same way these native tools are used - First you have to enter the folder that contains them, but then you just type in their name and hit enter. Say you're in your UFO folder, and you want to start the game - Usually in Windows, you'd double click the "ufocd" file, in this case we just type "ufocd" into the prompt and hit enter. Easy.

What are the benefits of running programs this way, besides our ability to use parameters? Well, say we ran UFO under Windows, and the game jumped up on the screen, but then crashed right away - Windows shuts it down, and it's gone, not on your screen anymore. But what if we ran it via the Command Prompt? Sure, it'll still most likely crash, but now any information it might have given us when it did so is left on the screen for us to read! This makes solving the problem much, much easier.

File Management

This section briefly goes over making directories (to store your files), removing directories and several ways you can manipulate your files: copying, moving, renaming, deleting. Along with cd, which was mentioned earlier, these make up a core set of basic commands that are used to manage files and folders.

These commands are also not necessarily confined to the Dos Console. In fact, many if not all of them, particularly in their extended names (mkdir, rmdir, chdir, etc) , are present in other operating systems that operate via a console, such as Linux and Unix - if perhaps differing in syntax.

Note that most of the file manipulation commands can make use of wildcards - but examples on how to use them (and their results) will not be covered here in great detail. Only the basic operations will be mentioned.


Making/Removing directories

You know how to navigate your hard drive. Now how do you create new directories so that you can organize your files? This can be done by way of the md, short for Make Directory. Alternately you can also use mkdir - which is exactly the same, but has three extra letters. This is basically the manual process of creating a folder, as you would through Explorer.

Creating a directory is simple, and all you need to do is type in the name of the directory after md and hit enter. For example, we want to make a directory called helpdocs, so we can store game guides collected off the internet for all your games.

md helpdocs 

If, say this folder already exists and you suddenly decide to create a sub folder (let's call it walkthrough) in it to organize it further, you can cd into it and add it manually. Alternately, you could type this

md helpdocs\walkthrough

This creates walkthrough in helpdocs. You can indeed type in a full path name, and it will only create the new folder at the end.

What would've happened if helpdocs does not exist when you type the above line? Ah, magic. md will create both the main helpdocs directory and the walkthrough subdirectory as well.

Okay, we've created a directory. How do we get rid of them? First of all they have to be empty of files. Then to remove the directory, you type rd or rmdir followed by the name (or path of the directory that you wish to remove. That's it. To remove helpdocs, we'd type:

rd helpdocs 

This will obviously not work if you still had the walkthrough subdirectory inside it. To remove that before you do the above, cd into helpdocs and remove walkthrough manually, or just type:

rd helpdocs\walkthrough

Note that unlike md, typing a full path will only remove the directory at the very end of the path, not the entire path if it ends up empty.

Copying

Copying a file is achieved by using copy, followed by the target and the source file, in that order. The most obvious use is to make backups of files. Let's say we had a called savegame.dat, and we'd like to make a backup called savegame.bak. Just type:

copy savegame.dat savegame.bak 

Let's say this file is stored somewhere else on the hard drive, but not in the one you're currently in. Let's say it's in d:\games\a_game. If you wanted to copy the file from there and place it directly into the current directory, just type

copy d:\games\a_game

The destination is assumed to be the current directory. What's happening is that copy is parsing the statement as:

copy d:\games\a_game\savegame.back .\ 

Note the dot, which symbolically refers to the current directory.

A most unorthodox use of copy is as a primitive text editor for creating very simple text files, such as a batch file. Try this on for size:

copy con filename.txt

Then type in something like Hello World. Note that if you press enter, you'll not be able to return to the previous line. To finish up, press ctrl+z followed by enter. Note that 1 file will be copied. You'll then find a file in that directory called filename.txt, and if you open it you'll find your text in the file. Con here is a symbolic reference that the console uses to refer to - surprisingly enough - the console. Or to be more precise, keyboard input.

You are better off using a proper text editor for these things, but this is valid way of creating a very simple file.

Moving

So you've copied a file into the current directory. Oops, it's meant to go in one of the sub directories! In Explorer, you'd move a file by simply dragging it into the subfolder (or some other location on the hard drive). In the command console, this is achieved through the move command. Like copy, it takes the source and a destination directory and filename. As long as the source and destinations are valid - and aren't identical, move will move the file.

Let's say we have a sub directory called docs\. We have a file called tables.doc in the current directory. To move this file into docs\, we'd type:

move tables.doc docs\

Note that the backslash was included to implicitly indicate that it's a directory we are moving into. If you left it off, move will check to see that the docs\ directory exists before making the move. If it does not exist, it'll end up renaming the file instead! Which would achieve the exact same effect as ren/rename (which will be mentioned shortly)!

Like copy, move can also be used to move a file from another directory into the current directory by using

move docs\tables.doc

This will effectively move the tables.doc file that we moved into docs back into the current directory.

Renaming

You may want to rename a file or directory. To do this, use ren or rename. It uses the common syntax that is used by copy and move, and takes two parameters. The target name, and the destination name. This can be used on files or directories.

Let's say we made a new directory called organes\ when we meant to create a directory called oranges\. To fix this, we type

ren organes oranges

For files, don't forget to supply the extension name as well.

Deleting

! ! Warning ! !

This is probably one of the most destructive commands you'll get to use in the console (next to the commands that format floppy and hard drives, obviously). So it cannot be stressed enough that you treat this command with the utmost respect and always - always - make sure you know what you're doing when you decide to delete a file through the console.

It's especially dangerous when paired with the wildcards. Deleting a file through the console doesn't throw the file into the recycle bin. It's deleted permanently - sort of like when you select files in the Explorer and then delete them by pressing shift+del.

Now, to actually delete a file, you use the del or erase command. It only takes one parameter and that is the file that you wish to delete.

Let's say we have a hapless file called goodbye.txt that we no longer need. To delete it, you would type

delete goodbye.txt

And that's it. It is gone. You'll never see it again - at least not unless you have tools that can dig into your hard drive and look up the sectors that was previously occupied by that file.

Note that if you supply a global wildcard (* or *.*) to delete all the files, you may be prompted whether you wish to do this. Also note that if you supply a directory name to del, it will assume that you wish to delete all the files in that directory, not the directory itself.

Once again it must be stressed that unless you know what you are doing, be very careful with del. If you are uncertain, use File Explorer instead to delete any local files as it has the safety buffer of the Recycle Bin (or similar service).

File Paths/Locations

Look at your command prompt. That shows you where you are on your current disk drive. You can reference any file on the computer by attaching the entire path before the filename.

For example, you are in c:\games and you'd like to open a file c:\notes\shopping\weekly\list.txt with MS-Edit, but you don't want to change from your current directory. To open the file, you would type:

edit c:\notes\shopping\weekly\list.txt 

And the file would be open. Similarly, you could use dir to do a directory listing of that very same directory with:

dir c:\notes\shopping\weekly\

When you do directory listings, you may have noticed two extra files in the list called . and .., which don't mean much by themselves.

On many OSs, not just in the dos console or Windows Explorer, these are symbols that are used to refer to the current directory (single dot) and the previous directory (double dot). The single dot is rarely ever needed while the double dot is very handy.

Let's say we're in c:\games\xcom and you've been keeping some game notes in a file named notes.txt store in c:\games\

To use MS-Edit to open that file without exiting c:\games\xcom, you can type

edit ..\notes.txt 

Another method is to type the full path, but this is much faster.

We can indeed string several together. Let's say we were in c:\games\xcom\geodata and we wanted to change to c:\games\tftd\, we'd type:

cd ..\..\tftd  
 

A compltely useless use of the double dot is to go back out a directory and then come back into the directory. Take this example, assume we are in c:\games\

dir ..\games

This results in dir doing a plain directory listing of the directory we are already in.

File names wild cards

So far we've only been handling single files. However, many of the console commands are designed to not only work on a single file, but sets of files. Dir for example is a powerful tool not just for displaying the list of files, but for finding files as well (in the current/sub or even specified directories). But what if we want to find more than one file?

To work with set of files, we can use what are known as filename wildcards. These are ? and *. Of the two, you may be most familiar with *, as many Windows Explorers file pickers have *.* shown when you want All Files to be displayed rather than the program's default format.

What do these two symbols mean? The ? means a single random character, while * means any numbers of random characters. Note that both versions apply to 0-1 and 0-n random characters respectively.

For the all of these examples, we'll assume that you are in your X-COM UFO or TFTD directory. It is also assumed that some save game files are present. All of the examples will done with dir. Since we want to perform searches of all sub directories, we'll need to run dir with the /s switch. And just to be safe, we'll pause each screen of information with the /p switch.

First, let's say that you'd like to see a list of all the files that have the tab extension. We'd then type:

dir /s/p *.tab 

Dir will then list all instances of all the tab files, showing their path and pausing on each screen of information.

What if we wanted to find all instances of the files that begin with Back? with the scr extension? We'd use:

dir /s/p back*.scr 

The back*.scr files are for the background images by the way.

Let's modify the last example so that we list all the back*.scr files that end with 2. We'll use ? in this example.

dir /s/p back?2.scr

We could have easily used * in the above example as well. The ? implicitly expects that no or 1 character are present before the next character while * can be any characters will appear before the next character.

Let's say we now want to find all instances of files that begin with an S and end with a P. Any extension. We would therefore us this:

dir /s/p s*p.*

This should bring up instances of seemap.dat and sourcemp.dat from your savegame folders.

Let's get creative. Let's look for all the files that begin with U, have a random characters, then an I, then anything else. We'd look for:

dir /s/p  u*i*.* 

You'd get a listing files that would include several instances of unitpos.dat, unitref.dat, uiglob.dat, uniref.dat, unipos.dat, uniref2.dat,

Let's refine it a little. Now we want it to end with at least one O followed by at least one random character.

dir /s/p  u*i*o?.* 

This would refine the search down to the instances of unitpos.dat, uiglob.dat and unipos.dat

As you can see, you can really refine your search down to a particular set of files.

Remember that these wildcards will work in Windows file open windows as well.

Please note that earlier versions of the dos console (up to the Windows 98 VM) were a bit lax in the use of wildcards and would interpret a dir *. as dir *.*. This is not the case in Windows XP and beyond and is treated as a search for files with no extension. A dir * still work like a dir *.*.

PATH environment parameter: calling programs from elsewhere

When you type in a command, the OS goes through a sequence of searches in order to find the name of the file, or command that you typed in.

First, it'll check if the file name you entered is an internal command, like dir. If it cannot find it, it will next check the current directory for the file. If it still cannot find the file, it will then go through all the directories that are specified in the PATH field.

In other words, you might keep a game editor in another directory, but you will be able to call it from another and use it in your current directory as if it were a native file. Note that this only applies to running programs. You cannot open a file in another directory this way.

The PATH field is a string of file paths separated by semicolons. You can see your path field by typing path with no parameters and pressing enter.

There are many other ways you can view your paths. Two simple methods involve the set command. Simply type in set and you will get a listing of all your console parameters, including the path. Or, type set path with no additional parameters to just view the path settings. A clever way of viewing your path can be done with echo %path%.

To manipulate your path settings, read the path /? help screen to better understand it.

All you need to do is type in path and then enter all the directory names after it, separating each one with a semicolon. Remember that you need to use parenthesis for long names with spaces.

Each console line unfortunately only allows 255 characters per line, so you may sometimes not have enough space to all your paths. No worries. You can place a copy of the existing path into the path you're entering with %path%. For example:

Let's say your existing path looks like:

path = c:\; c:\windows; 

If you want to add a few new paths to the above but not have to retype what was in their previously, use:

path c:\games\ufo ; "e:\misc utilities and editors"; %path% 

This will result in a path that looks like:

path = c:\games\ufo ; "e:\misc utilities and editors"; c:\; c:\windows;

Note that you can also set the path parameter by using the set command. The only difference is that while path would look like:

path %path%; c:\mypaths 

Set would look like

set path=%path%; c:\mypaths

Otherwise the two above actions will have an identical effect.

Long Filenames

Early versions of FAT supported filenames made up of a maximum of eight characters, with a three letter extention. FAT32/NTFS supports much longer filenames, however, DOS programs still need to stick to the eight character rule. Notes as to how to deal with this still to come.

Advanced Techniques

Redirection

Though you may never need to use this for every day use, this section will briefly mention what redirection is and what you can do with it. To put it in simple terms, it's redirecting output (text on the screen or a file) to somewhere else (a file, the printer, etc).

Try this command from the command prompt:

dir > dirlist.txt

Nothing will appear to happen. Do a plain dir immediately afterwards. Notice that there'll be a new file in the directory called dirlist.txt. Open it. Surprise! The directory listing you didn't see has now ended up in this file. It may even include a 0 byte copy of dirlist.txt. Don't worry - this happened only because the file came into existence before it was populated. Feel free to delete it afterwards.

Here's another exciting variation that hides text output. This can be very handy when working with batchfiles that run other programs but you don't want their text to be displayed.

dir > nul 

What happens? Nothing appears, you just get thrown right back to a clear command prompt.

Note that nul is nul, not null. Passing a null would create a file could null. nul is a special character that Dos treats as nothingness. Oblivion. Nowhere. So by piping the output of a dos program to nul, nothing appears on the console. Be aware that some console programs aren't always affected by this.

Please note that this is not the same as using the @ symbol or Echo off to hide the sequence of commands that are processed through a batch file.

(In C jargon, these programs also use stderr rather than just stdout. If you really want these high priority-messages to go the same place as the normal messages, tie stderr to stdout like this:

dir 2>&1 > dirlist.txt
dir 2>&1 > nul 

)

In another instance, redirection can also be used to pass the output of one program to another. This is done by way of piping with the | symbol. Go to your X-COM directory and see if the readme.txt file is present. Enter the following line:

type readme.txt 

Notice how the whole screen flashes by before you've had a chance to read it all. Now, try this:

type readme.txt | more 

A quick overview of the two commands type and more.

Type dumps the contents of the file you specify directly onto the screen. More is a command in dos that lets you display text one screen at a time.

You'll now have the screen pause after each page full. Just press the space bar to continue, or press ctrl+c to break out of it. You normally use it like any other dos command, but piping it this way is merely an alternate method of doing it.

This is actually a rather primitive method of displaying a text file, but quick if you just want to dump the contents onto the screen quickly rather than open a text editor.

Another method of performing the last example is to use input redirection.

First make a text file and populate it with the following lines:

ball
dog
cat
apple
dog

Let's call it list.txt. Notice that there is indeed a second dog.

After making the file, enter:

sort < list.txt 

Very briefly, sort will reorder the text that's in list.txt so that each line is in alphanumerical order. You should see:

apple
bal
cat
dog 
dog 

This is only displayed on the screen. What if you wanted to save this output to a file called sortlist.txt? We do this:

sort < list.txt > sortlist.txt

Now let's get stupid brave and combine all three. First a quick introduction to find, which we'll be using in the next example.

Find takes a string as a parameter and then searches through the file (or files) for all instances of lines that contain the string you specified and then dumps the line(s) onto the screen.

Anyhow, let's say we want to go through the readme.txt file in your XCOM directory and get all the lines that have the instance of the word "UFO", then you want to sort all the lines and then save the result into a text file called ufolines.txt. You can do all this at once by using:

find "UFO" < readme.txt | sort > ufolines.txt 

While the above is a very clumsy way of doing this, and possibly very prone to mistakes, it still demonstrates how they can all be thrown together.

Coincidentally, the contents of ufolines.txt, assuming you were testing this line on X-COM UFO's readme file, should read:

INSTALL.BAT C:\UFO
installation, run the setup program in your UFO directory.
UFO runs in protected mode so it does not require an expanded memory

There are many more exciting things you can do with redirection , but this article only covers the basics, and they would be beyond the scope of this article.

Batch Files

This article will only cover the basics of batch files. The most basic of basics. It would require a whole article of its own to describe most of the things you can do with batch files.

A batch file is simply a plain unformatted text file with the extension BAT. It basically runs each line in the file as if they were entered directly into the command prompt in sequence.

For example, let's say we always do two actions near each other over and over again. In this case, we have a file and a backup of that file. Let's call them savefile.dat and savefile.bak respectively. We often delete the current version of savefile.dat and then make a copy of savefile.bak to replace it. To do this, we'd type in these two commands:

del savefile.dat
copy savefile.bak savefile.dat

Yep, we'd have to do this each and every time we wanted to restore the old file. It's a two step process. To make this a one step process, open a plain text editor like MS-EDIt or Microsoft Notepad (or any editor of your choice - just remember to save it as plain text), then type the above commands into it. Press enter after each line. Now save it as r.bat in the same directory that you are working on. Every time you want to restore the backup copy, all you'd have to do is type r and hit enter. That's it. Quick and simple. For completeness sake, he's a set of commands you could to as a companion to r.bat - q.bat, which makes a backup of the current copy of savefile.dat

del savefile.bak 
copy savefile.dat savefile.bak

That's just a simple example of how to use a batch file. However, batch files are more than just simple macros. The command console does have a series of commands that are built specifically for batch files in mind, such as echo, pause, for, goto, call, if, rem and shift.

In a way, you can think of batch files as miniature programs, or scripts. The above commands give them additional functionality and program flow control. This quick overview will not cover any of the above.

For those interested, the dos versions of X-COM UFO and TFTD are notorious for having their main game loop encapsulated in a simple batch file. Though some later versions disguise this by converting the batch file into a .com file, they are still at their core constructed from a batch file. XCOMUTIL provides its own batch file replacement for the game in the form of runxcom.bat and runxcomw.bat (for the CE editions). If you're interested, open up the batch files in a text editor or word processor and have a look at the heart that runs the game.

Extra Tools

Need notes about:

DosBox (another Dos VM that can emulate old hardware) - many (but not all) of MS-Dos simpler commands like dir and cd are emulated in. It doesn't recognize every variation of some basic commands, but you can get around this.

MoSlow (a program that causes programs to run slower on too-fast machines)

VDMSound (a collection of tools that aid the MS DOS VM, most notably sound card emulation), and anything else that might be useful

Extra Stuff

More stuff that could be added.

  • What can you do with all this in the context of playing X-Com? And more