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