The bastard love child of BAT and WSH

The (default) PATHEXT environment variable contains .vbs/.js/.wsf but wscript.exe is usually set as the default windows scripting engine host, so running scripts in a terminal is a big pain. What if we could put the WSH script inside a batch file so we don’t have to prefix every call with cscript //nologo ?

@if (1==1) @if(1==0) @ELSE
@echo off&SETLOCAL ENABLEEXTENSIONS
cscript //E:JScript //nologo "%~f0" %*
@goto :EOF
@end @ELSE
WScript.Echo("hello from WSH");
@end

If there ever was a huge scripting hack, this is it. Somehow it is both “valid” BAT and JScript syntax! The @if syntax requires MS:JScript v3 (IE4+), on the batch side of things, %~f0 and %* requires at least NT4, maybe NT5.

Advertisements

Tags: , , ,

2 Responses to “The bastard love child of BAT and WSH”

  1. tuxplorer Says:

    Why don’t you blog any more? I LOVED your blog entries (and the topic) šŸ˜‰

  2. jimmy Says:

    This is ugly genius. I love it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s