batch-filejscript

JScript + batch hybrid file: removing the "script host" text


I have a JScript-batch hybrid file and it works fine, but the cscript command outputs some unwanted text:

Microsoft (R) Script host for Windows, version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

I know this is a copyright notice, but I'm only using this program on my PC. It's quite annoying. This is the code:

@if (@a==@b) @end /*

:: batch portion

@ECHO OFF

cscript /e:jscript "%~f0"

pause


:: JScript portion */

function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    };
  };
};

var n = 0;
while (true) {
    n = n+1;
    i = n;
    WScript.Echo(i)
    if (i==1) {
        WScript.Echo("----");
        sleep(1000);
    } else {
        while (i!==1) {
            sleep(500);
            if (i%2==0) {
                i = i/2;
            } else {
                i = 3*i + 1;
            };
            WScript.Echo(i)
        };
    WScript.Echo("----");
    sleep(1000);
    };
};

I've tried using WScript.Shell and using exec() to execute cls, but it simply doesn't work.


Solution

  • If you add the //nologo switch to the cscript command, the message will be suppressed.

    cscript /e:jscript "%~f0" //nologo