Difference between revisions of "Command Prompt"

From UFOpaedia
Jump to navigation Jump to search
m (Finally added a brief section on piping)
Line 132: Line 132:
 
== Piping ==
 
== Piping ==
  
<i>The option to divert the output of a command to a text file. This section still to come.</i>
+
This section just briefly mentions what piping is and what you can do with it. You would probably rarely ever find an occasion to use piping, but are mentioned for completeness.
 +
 
 +
Piping allows you to redirect text to another source, such as a text file.
 +
 
 +
Try this command from the command prompt:
 +
 
 +
dir > dirlist.txt
 +
 
 +
Nothing will appear to happen. In the first instance, 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. 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.
 +
 
 +
In another instance, piping can also be used to pass the output of one program to another. 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
 +
 
 +
Just a quick overview of "more" - it's a command in dos that lets you display text one screen at a time. Use ctrl+c to break out it at any 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.  
  
 
== Paths ==
 
== Paths ==
Line 182: Line 212:
 
<i><b>Need notes about:</b>
 
<i><b>Need notes about:</b>
  
[[DosBox]] (another Dos VM that can emulate old hardware)
+
[[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)
 
MoSlow (a program that causes programs to run slower on too-fast machines)
Line 190: Line 220:
 
== Extra Stuff ==
 
== Extra Stuff ==
 
More stuff that could be added.
 
More stuff that could be added.
<pre>
+
*Filename wildcards (* and ?)
Filename wildcards (* and ?)
+
*Batch files  
Batch files  
+
*Utterly Horrible Commands That You Should Never Use Unless You Know What You're Doing
Utterly Horrible Commands That You Should Never Use Unless You Know What You're Doing
+
*What can you do with all this in the context of playing X-Com? And more
What can you do with all this in the context of playing X-Com?  
 
And more
 
</pre>
 

Revision as of 05:21, 10 April 2009

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 DOS

Using DOS is just a matter of typing stuff in and pressing enter. To demonstrate this, I'll start you off with the "dir" command.

Of the two command lines available the Windows Command Prompt 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 Command Prompt: 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 set out the same way mine is, 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 practise 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 what operating system you're using, 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

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 Manipulation

The use of the "copy", "move" and "del" commands. This section still to come.

Piping

This section just briefly mentions what piping is and what you can do with it. You would probably rarely ever find an occasion to use piping, but are mentioned for completeness.

Piping allows you to redirect text to another source, such as a text file.

Try this command from the command prompt:

dir > dirlist.txt

Nothing will appear to happen. In the first instance, 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. 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.

In another instance, piping can also be used to pass the output of one program to another. 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 

Just a quick overview of "more" - it's a command in dos that lets you display text one screen at a time. Use ctrl+c to break out it at any 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.

Paths

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.

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.

  • Filename wildcards (* and ?)
  • Batch files
  • Utterly Horrible Commands That You Should Never Use Unless You Know What You're Doing
  • What can you do with all this in the context of playing X-Com? And more