samples/exec.js

Fri, 07 Aug 2015 11:55:46 -0700

author
asaha
date
Fri, 07 Aug 2015 11:55:46 -0700
changeset 1498
3be31159ea48
parent 1405
98b090e45df3
child 1819
5e1012e665bf
permissions
-rw-r--r--

Added tag jdk8u72-b00 for changeset 667e020da337

mhaupt@1403 1 # exec script requires -scripting mode
mhaupt@1403 2
mhaupt@1403 3 /*
mhaupt@1403 4 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
mhaupt@1403 5 *
mhaupt@1403 6 * Redistribution and use in source and binary forms, with or without
mhaupt@1403 7 * modification, are permitted provided that the following conditions
mhaupt@1403 8 * are met:
mhaupt@1403 9 *
mhaupt@1403 10 * - Redistributions of source code must retain the above copyright
mhaupt@1403 11 * notice, this list of conditions and the following disclaimer.
mhaupt@1403 12 *
mhaupt@1403 13 * - Redistributions in binary form must reproduce the above copyright
mhaupt@1403 14 * notice, this list of conditions and the following disclaimer in the
mhaupt@1403 15 * documentation and/or other materials provided with the distribution.
mhaupt@1403 16 *
mhaupt@1403 17 * - Neither the name of Oracle nor the names of its
mhaupt@1403 18 * contributors may be used to endorse or promote products derived
mhaupt@1403 19 * from this software without specific prior written permission.
mhaupt@1403 20 *
mhaupt@1403 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
mhaupt@1403 22 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
mhaupt@1403 23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
mhaupt@1403 24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
mhaupt@1403 25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
mhaupt@1403 26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
mhaupt@1403 27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
mhaupt@1403 28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
mhaupt@1403 29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
mhaupt@1403 30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
mhaupt@1403 31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mhaupt@1403 32 */
mhaupt@1403 33
mhaupt@1403 34 // The $EXEC builtin function can be used to run external commands:
mhaupt@1403 35 $EXEC("ls")
mhaupt@1403 36 $EXEC("ls -la")
mhaupt@1403 37
mhaupt@1403 38 // It can also be given a string to use as stdin:
mhaupt@1403 39 $EXEC("cat", "Hello, world!")
mhaupt@1403 40
mhaupt@1403 41 // Additional arguments can be passed after the stdin argument, as an array of
mhaupt@1403 42 // strings, or a sequence of varargs:
mhaupt@1403 43 $EXEC("ls", "" /* no stdin */, "-l", "-a")
mhaupt@1403 44 $EXEC("ls", "" /* no stdin */, ["-l", "-a"])
mhaupt@1403 45
mhaupt@1403 46 // Output of running external commands is returned from $EXEC:
mhaupt@1403 47 print($EXEC("ls"))
mhaupt@1403 48
sundar@1405 49 // apply on $EXEC
sundar@1405 50 print($EXEC.apply(this, ["ls"]));

mercurial