VOGONS

Common searches


First post, by Osprey

User metadata
Rank Member
Rank
Member

DOSBox supports only a subset of real DOS commands. One particularly useful one that's missing is the FOR command. Here's how you can add it (and other missing commands) and use it, with an example given of how to automatically mount ISOs, which is pretty handy. (Edit: DOSBox SVN-lfn now has built-in FOR support. For other builds, including the official one, though, use the following instructions)

1. Download the 4DOS 8.00 binaries from 4dos.info. 4DOS is a replacement command interpreter.
2. Extract 4DOS.COM (that's all that you need) to a folder that you intend to mount. I prefer to keep it where Dosbox.exe is, with the rest of my non-game files.
3. Whenever you want to use a DOS command that 4DOS supports (like FOR), run:

<path>\4DOS.com /c <command>

(Tip: If you do "path Z:\;<path>" (ex. "path Z:\;C:\DOSBox") first, then you don't have to specify the path or change to the directory whenever you call 4DOS.com)

For example, for the FOR command:

4DOS.com /c for %f in (<set>) do <command>

...or, if in a batch file or dosbox.conf's [autoexec], the % must be doubled, like so...

4DOS.com /c for %%f in (<set>) do <command>

For a real world example, here's a dosbox.conf's [autoexec] section:

[autoexec]
@echo off
mount c .
c:
4DOS.com /c for %%f in (*.iso,*.cue) do imgmount d %%f -t iso
cls

That mounts the first .iso or .cue file that it finds in the current directory. For example simplicity, the ISOs, 4DOS.com and DOSBox.exe are all assumed to be in the same folder, which is mounted as drive C. Obviously, you would add the appropriate paths for your actual configuration.

To make it more powerful and handle more than one ISO (particularly for multi-game CDs), you can expand it to this:

[autoexec]
@echo off
mount c .
c:
4DOS.com /c for %%f in (*.iso,*.cue) do echos "%%f" > cdlist.txt
4DOS.com /c for /f %%f in (cdlist.txt) do (imgmount d %%f -t iso && del cdlist.txt)
cls

That will mount all ISOs that it finds as drive D so that you can swap between them with CTRL+F4. If you have games with multiple CDs, this can be very handy. I wanted this so that I could just copy one or more ISOs to a folder and have them automatically mounted without me having to edit [autoexec] and the imgmount commands for every game that I set up.

The only hitch with that method is that you can't carry variables between the commands, since 4DOS exits after each is run. That's why I had to store the ISO names in a text file and then read them back on the next line. If you're going to be using variables and, especially, calling 4DOS a lot, you're likely better off separating those commands out into a batch file and then simply having 4DOS run the batch file, like so:

[autoexec]
@echo off
mount c .
c:
4DOS.com /c MountISO.bat
cls

...with MountISO.bat containing:

;; MountISO.bat
@echo off
for %%f in (*.iso,*.cue) do (set cdlist=%cdlist% "%%f")
imgmount d %cdlist% -t iso

That does exactly the same thing as the example above (mounts all ISOs as drive D). If you're just going to use 4DOS once or twice in a batch file, you may just want to use the first method and invoke 4DOS for each command, but, if you plan to do some more serious scripting, you may want to use the second method and invoke 4DOS to run whole batch files. Something that's really nice, as you can see, is that DOSBox's commands (like imgmount) continue to be accessible even when you're in the 4DOS environment, so there doesn't really appear to be any downside to putting all commands in batch files and executing them in 4DOS, except for the minor inconvenience of having extra files to edit.

Here's Microsoft's reference for the FOR command (with a list on the left of all of the other DOS commands):

https://technet.microsoft.com/en-us/library/bb490909.aspx

Of course, 4DOS can be used for more than just FOR. I also used its ECHOS command above (because regular ECHO always adds a newline character).
Here's a complete list of the available 4DOS commands that you can use:

?           ALIAS       ATTRIB      BEEP        BREAK       CALL
CANCEL CASE CD CDD CHCP CHDIR
CLOSETRAY CLS COLOR COPY COUNTRY CTTY
DATE DEFAULT DEL DELAY DESCRIBE DIR
DIRHISTORY DIRS DO DRAWBOX DRAWHLINE DRAWVLINE
ECHO ECHOERR ECHOS ECHOSERR EJECTMEDIA ENDLOCAL
ENDSWITCH ERASE ESET EXCEPT EXIT FFIND
FOR FREE FUNCTION GLOBAL GOSUB GOTO
HEAD HELP HISTORY IF IFF INKEY
INPUT KEYBD KEYSTACK LFNFOR LH LIST
LOADBTM LOADHIGH LOG MD MEMORY MKDIR
MOVE ON OPTION PATH PAUSE POPD
PROMPT PUSHD QUIT RD REBOOT REM
REN RENAME RETURN RMDIR SCREEN SCRPUT
SELECT SET SETDOS SETERROR SETLOCAL SHIFT
SWAPPING SWITCH TAIL TEE TEXT TIME
TIMER TOUCH TRANSIENT TREE TRUENAME TYPE
UNALIAS UNFUNCTION UNSET VER VERIFY VOL
VSCRPUT WHICH Y

I haven't tested most, but I recognize a bunch as MS-DOS commands that DOSBox doesn't natively support, so I imagine that you could use 4DOS to do just about anything in DOSBox that you could in real MS-DOS.

Anyways, hopefully, some people will find this useful in their scripting, as I have.