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!


NEW online workshop: WebStandards Igniter (online)

Airport MUC workshops: Java EE 8, Java 9: Bootstrap, Effective, Architectures, Single Page Apps, Progressive Web Apps, HTML 5, ES 6, CSS 3 and Microservices

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

Comments:

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