Running DOS Programs

  

Next Topic

 

The WIL Tutorial

 

Getting started

Using WIL

Reference

Notes

 

WIL can run DOS programs, just like it runs Windows programs:


DirChange("c:\game") Run("scramble.exe", "")

If you want to use an internal DOS command, such as DIR or TYPE, you can do so by running the DOS command interpreter, CMD.EXE, with the /c program parameter, as follows:

Run("cmd.exe", "/c type readme.txt")

Everything that you would normally type on the DOS command line goes after the /c in the second parameter. Here's another example:

Run("cmd.exe", "/c type readme.txt | more")

These examples assume that cmd.exe is in a directory on your DOS path. If it isn't, you could specify a full path name for it:

Run("c:\windows\system32\cmd.exe", "/c type readme.txt | more")

Or, better still, you could use the WIL Environment function.

 

Environment (env-variable)

Gets a DOS environment variable.

Since DOS always stores the full path and filename of the command processor in the DOS environment variable COMSPEC, it is an easy matter to retrieve this information:

coms = Environment("COMSPEC")

and use it in our WIL program:

coms = Environment("COMSPEC") Run(coms, "/c type readme.txt") Exit

To get a DOS window, just run CMD.EXE with no parameters:

coms = Environment("COMSPEC") Run(coms, "") Exit

 
64-bit Windows Architecture

When running WinBatch on a system with 64-bit architecture, you must deal with is something called File Redirection. For example, when launching the Windows Command Shell (CMD.EXE), Windows decides automatically which bit depth to load, depending on the calling application. e.g. 32 bit for 32 bit, 64 bit for 64 bit.

; On a 64-bit Architecture ; By default 32-bit WinBatch launches the 32-bit CMD.EXE ; By default 64-bit WinBatch launches the 64-bit CMD.EXE Run( Environment("COMSPEC"), "" ) Exit

What if you don’t want that? Then you must explicitly run specific bitness of CMD.EXE by specifying full path name, as follows:

To explicitly run the 32-bit version of a command:

cmd_32 = DirWindows(0):"\syswow64\CMD.EXE" Run( cmd_32, "" ) Exit

To explicitly run the 64-bit version of a command:

cmd_64 = DirWindows(0):"\sysnative\CMD.EXE" Run( cmd_64, "" ) Exit