WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

64-bit

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

CMD File Redirection

 Keywords: Environment COMSPEC CMD CMD.EXE Command Shell 32 64 32-bit 64-bit Start Launch Run RunWait ShellExecute SysNative SysWow64

Question:

I am starting the CMD.EXE from my WinBatch Script. If you start the Command Shell from a 32-bit script the 32bit then CMD.EXE will be started and if I start the Command Shell from a 64-bit script then a 64-bit CMD.EXE is launched. In some cases 32 and 64bit CMD.EXE is acting different.

How can I launch the 64-bit CMD.EXE from my 32-Bit WinBatch script?

Answer:

What you are dealing with is something called File Redirection. 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

Article ID:   W17643
Filename:   CMD File Redirection.txt
File Created: 2013:05:15:13:14:06
Last Updated: 2013:05:15:13:14:06