Java Reference
In-Depth Information
The following is the output of using some of the utility functions provided by
jrunscript :
C:\>jrunscript
nashorn> cat(" http://jdojo.com/about ", "ksharan")
68 : <p>You can contact Kishori Sharan by email at <a
href=" mailto:ksharan@jdojo.com "> ksharan@jdojo.com < /a>.</p>
nashorn> var addr = read("Please enter your address: ", 1);
Please enter your address: 9999 Main St.
Please enter your address: Dreamland, HH 11111
Please enter your address:
nashorn> print(addr)
9999 Main St.
Dreamland, HH 11111
nashorn> which("jrunscript.exe");
c:\JAVA8\BIN\jrunscript.exe
nashorn>pwd()
C:\
nashorn>
Most of these utility functions have been written as Nashorn scripts taking advantage
of the Java class libraries. The best way to learn about how these functions work is to read
the source code. You can print the source of nonnative functions by simply entering the
function name at the nashorn command prompt. The following sequence of commands
shows you how to print the source code for the exec(cmd) function. The output shows
that the function uses the Java Runtime class internally to run the command:
c:\>jrunscript
nashorn> exec
function exec(cmd) {
var process = java.lang.Runtime.getRuntime().exec(cmd);
var inp = new DataInputStream(process.getInputStream());
var line = null;
while ((line = inp.readLine()) != null) {
println(line);
}
process.waitFor();
$exit = process.exitValue();
}
nashorn> exit()
c:\>
Search WWH ::




Custom Search