From raster@highfiber.com Mon Sep 30 23:08:42 2002 Newsgroups: alt.msdos.batch Subject: Win95Cmd piping, was: Batch File for Win XP From: raster@highfiber.com (Charles Dye) Date: 30 Sep 2002 21:08:42 -0700 On Mon, 30 Sep 2002 15:35:48 +0100, "William Allen" wrote: >c) Using Pipes > >You'll find that a direct pipe operation won't work in a Win95cmd >custom DVM. Actually, piping *does* work in Win95Cmd with a very trivial tweak. The problem is so stupid I'm actually ashamed it took me this long to figure it out. Here's the scoop: Win95Cmd, like CMD.EXE and 4NT but unlike COMMAND.COM and 4DOS, supports true pipes: both sides of the pipe run simultaneously in separate command shells. When a command like type c:\autoexec.bat | more is encountered, Win95Cmd spawns a second command shell as a separate process, passes it the command-line arguments /S /D /c"type c:\autoexec.bat" and pipes the output from that shell back to the original instance of Win95Cmd, which in turn runs MORE with input from the pipe. The second instance of the command shell is launched using the COMSPEC environment variable -- and therein lies the problem. In DOS environments (including Windows 95/98/Me) COMSPEC will point to a shell like COMMAND.COM or 4DOS, which won't know what to make of those strange command-line arguments! If COMSPEC points to Win95Cmd instead, pipes will function as intended. The programmer who ported Win95Cmd really should have made the program record its own pathname at startup and used *that* to spawn pipe shells, rather than the COMSPEC variable. We only want COMSPEC to point to Win95Cmd within that program; it should point to an MS-DOS shell the rest of the time. Probably the simplest way to arrange this is to plug an appropriate SET command into Win95Cmd's autorun registry key: HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun Make it a string value, for example "set comspec=c:\bin\util\win95cmd.exe" If the executable is in your search path, you can probably get away with "set comspec=win95cmd.exe" but I recommend the full form. While you're in there, you might as well create a doubleword value named CompletionChar and give it a value of 9, to assign filename completion to the Tab key like more professional shells. Once this tweak is made, you can experiment with true piping instead of the temp-file emulation provided by single-tasking DOS shells like COMMAND.COM and 4DOS. Enjoy! Microsoft Windows 2000 [Version 4.10.0000] (C) Copyright 1985-1999 Microsoft Corp. D:\WINDOWS\Desktop>set | sort BLASTER=A220 I5 D1 H5 P330 T6 E620 CMDLINE=win COMSPEC=c:\bin\util\win95cmd.exe PATH=D:\WINDOWS;D:\WINDOWS\COMMAND;C:\NASM;C:\A86;D:\WINDOWS\BAT;C:\BIN\BAT; C:\BIN\UTIL;C:\BIN\4DOS;C:\BIN\ELVIS;E:\NU PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.JS;.WS PROMPT=$p$g TEMP=D:\windows\temp TMP=d:\windows\temp UNZIP=-C winbootdir=D:\WINDOWS windir=D:\WINDOWS D:\WINDOWS\Desktop> -- Charles Dye raster@highfiber.com