Changing Working Directories In Nashorn Scripting

Assigning a directory name to the $ENV.PWD variable: $ENV.PWD="[DIR_NAME]" changes the working directory for the next command:

The ls command will print the contents for directory specified earlier:


#!/usr/bin/jjs -fv
print('Tmp Directory');
$ENV.PWD='/tmp';
$EXEC('ls -al');
print($OUT);
print('Root Directory');
$ENV.PWD='/';
$EXEC('ls -al');
print($OUT);

Thanks to Jim Laskey for the hint

See you at Java EE Workshops at Munich Airport or dedicated / custom virtual workshops!


Web Apps, SPA, PWA with vanilla Java Script (ES 6+), CSS 3 and WebStandards only. As simple as possible, but not simpler. See you at: (Progressive) Web apps, Single Page Apps and WebStandards airhacks workshops at MUC airport, Winter Edition

airhacks.fm the podcast:

Stay in touch: airhacks.news.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
realworldpatterns.com
...the last 150 posts
...the last 10 comments
License