O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

There's more...

The shell scripting mode can be enabled in jjs using the -scripting command. So, one can embed Shell/Batch commands within the JavaScript code, as shown here:

var files = $EXEC("dir").split("\n");for( let file of files){  print(file);}

If you are using ES5 as the language for jjs, then you can replace $EXEC("dir") with `dir`. But in ES6, `` are used for representing template strings. The preceding script can be executed using jjs, as shown here:

$ jjs -scripting=true --language=es6 embedded_shell_command.jsembedded_shell_command.js  hellojjs.js  using_map_set_demo.js

There are two more variables available, $ARG and $ENV, which can be used to access the arguments passed to the script and the environment variables, respectively. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required