// -*- javascript -*- // hello world // print a simple string on stdout System.print("Hello World\n") // argv // access command line parameters (no segmentation fault accepted, nor silent exception, so some languages must explicitly check the presence of the argument) System.print(ARGS[1], "\n") // env // access environment variable System.print(System.getenv("HOME"), "\n") // test file exists // return exit code error (non zero) if a file does not exist if (!new File("/etc/mtab").exists()) System.exit(1) // test file readable // return exit code error (non zero) if a file is not readable if (!new File("/etc/mtab").open("r")) System.exit(1) // formatting // print integers in a simple formatted string a=1; b=2; System.print(a, " + ", b, " = ", a + b, "\n") // system // call an external program and check the return value if (System.system("false") != 0) System.error("false failed\n") System.system("echo done")