Call JS - file from batch - file. Print messages. Return error level

First way to call JS - file from batch - file - in command prompt:

script_name.js "argument1" "argument2"

And second way is - package-call in batch - file:

echo off
call :test
CScript //Nologo "script_name.js" "argument1" "argument2"
Set ERR=%ERRORLEVEL%
Echo %ERR%
Exit /b

For example during running inerpretation JS - file can print messages and return error level to batch - file that called it. Look JScript - file:

//Accept extern arguments
var oArgs = WScript.Arguments;
var firstItem = oArgs.Item(0);
var secondItem = oArgs.Item(1);

//Print messages include in variables or like that - WScript.Echo("test message");
WScript.Echo(firstItem);
WScript.Echo(secondItem);

//Close WScript object
WScript.Quit();
//Or can close Wscript object and return error level for example - equal "1" like //that - WScript.Quit(1);

Maybe it`s can help you in some cases by use that pseudo metods - print() and return() - in control the diferent events in scripting by batch - files.
It`s support by Microsoft Windows Script Host.

No comments :

Post a Comment