0
votes

the batch file is supposed to run numerous scripts sequentially (a script is dependent on its previous script). The problem is that the work will be completed successfully only when all the scripts run properly in order. Even if one script fails to run, we don't get the desired output. Here is the example of Batch script;

cd some\Relevant\Folder
script1.js
PING localhost -n 10 > NUL
script 2.js
PING localhost -n 10 > NUL
java -cp X:\some\Java\JavaDir JavaScript
PING localhost -n 10 > NUL
X:\some\bat\directory\batfile.bat
X:\some\directory\pythonfile.py

Here the .js files run properly. But .bat files do not run somehow and so .py script (which sends the mail also fails to run). However, when the .bat files were not present in the script, the .py script ran successfully (with desired result).

Is there any way that I can get the return code/exit code of specific statements like successful/unsuccessful runs of .js, .bat or .py files?

PS: I saw "echo %ERRORLEVEL%" solution on the Internet, but it just prints the error level only once (until it changes.. for example: Successful run gives the echo output as 0 only once.. if I echo it after another statement, it doesn't print anything. If I echo it after an unsuccessful run, it prints some other number like 9009...), even if I echo it the second time after another command.

1
Have you tried Call X:\some\bat\directory\batfile.bat? It would be better to use Timeout 10 > Nul instead of PING localhost -n 10 > NUL and using the Start "" /Wait CScript //NoLogo /E:JScript "script 2.js" syntax may prevent the need for guessing how long to wait for each jscript to complete too. - Compo

1 Answers

0
votes

I found a workaround to this. All the statements in the script were not running because even if one statement threw an error, the rest of the statements would not be executed. The workaround was the invoke a new shell of cmd for every script using,

cmd /c absolute\path\script2.js