XQuery/Execute External Process

Motivation

edit

You need to execute an external process such as shell command.

Execute Process Command

edit
  process:execute($command as xs:string, $options as node()) as item()*

Example of Options

edit

There are currently only two options documented. The working directory and the value of the standard input:

<options>
    <workingDir>PATH TO LOCAL FILE SYSTEM</workingDir>
    <stdin><line>INPUT STRING</line></stdin>
</options>

Sample Program

edit

XQuery File

edit
import module namespace process="http://exist-db.org/xquery/process" at "java:org.exist.xquery.modules.process.ProcessModule";

let $cmd := 'D:\Apps\git\bin\ls.exe'
return
<results>
{process:execute($cmd, <options/>)}
</results>

Sample Output

edit

Here is an example of the git "ls" command being run without any options. Note that the default is the EXIST_HOME directory.

<execution exitCode="0">
    <commandline>D:\Apps\git\bin\ls.exe </commandline>
    <stdout>
        <line>Install_V2.0_20130212155217_6931977091675999583.log</line>
        <line>LICENSE</line>
        <line>README</line>
        <line>VERSION.txt</line>
        <line>atom-example.xq</line>
        <line>atom-services.xml</line>
        <line>autodeploy</line>
        <line>backup.properties</line>
        <line>bin</line>
        <line>build</line>
        <line>build.bat</line>
        <line>build.properties</line>
        <line>build.sh</line>
        <line>build.xml</line>
        <line>client.properties</line>
        <line>client.properties.tmpl</line>
        <line>collection.xconf.init</line>
        <line>conf.xml</line>
        <line>conf.xml.tmpl</line>
        <line>descriptor.xml</line>
        <line>descriptor.xml.tmpl</line>
        <line>dist</line>
        <line>eXist-db.app</line>
        <line>examples.jar</line>
        <line>exist-optional.jar</line>
        <line>exist.jar</line>
        <line>extensions</line>
        <line>icon.bmp</line>
        <line>icon.ico</line>
        <line>icon.png</line>
        <line>index.html</line>
        <line>installer</line>
        <line>lib</line>
        <line>log4j.dtd</line>
        <line>log4j.xml</line>
        <line>mime-types.xml</line>
        <line>mime-types.xml.tmpl</line>
        <line>samples</line>
        <line>schema</line>
        <line>src</line>
        <line>start.jar</line>
        <line>test</line>
        <line>tools</line>
        <line>uninstall.jar</line>
        <line>vm.properties</line>
        <line>webapp</line>
    </stdout>
</execution>