http://www.zorba-xquery.com/modules/process

Description

Before using any of the functions below please remember to import the module namespace:

import module namespace process = "http://www.zorba-xquery.com/modules/process";
This module provides functions to create a native process and return the result (i.e. exit code, result on standard out and error).

Example:

  import module namespace proc = "http://www.zorba-xquery.com/modules/process";
  proc:exec("ls")

Potential result:

 <result xmlns="http://www.zorba-xquery.com/modules/process">
   <stdout>myfile.txt</stout>
   <stderr/>
   <exit-code>0</exit-code>
 </result>
 

Module code

Here is the actual XQuery module code.

Authors

Cezar Andrei

Version Declaration

xquery version "3.0" encoding "utf-8";

Namespaces

anhttp://zorba.io/annotations
processhttp://www.zorba-xquery.com/modules/process
verhttp://zorba.io/options/versioning

Function Summary

exec($cmd as xs:string) as element(process:result) external

Executes the specified string command in a separate process.

exec($cmd as xs:string, $args as xs:string*) as element(process:result) external

Executes the specified string command in a separate process.

Functions

exec#1

declare %an:sequential function process:exec(
    $cmd as xs:string
) as element(process:result) external

Executes the specified string command in a separate process. This function does not allow arguments to be passed to the command.

Parameters

  • $cmd

    command to be executed (without arguments)

Returns

  • element(process:result)

    the result of the execution as an element as shown in the documentation of this module. The exit-code element returns the exit code of the child process. For POSIX compliant platforms: returns the process exit code. If process is terminated or stopped: 128 + termination signal code. For Windows platforms: returns the return value of the process or the exit or terminate process specified value.

Errors

  • process:PROC01

    if an error occurred while communicating with the executed process.

exec#2

declare %an:sequential function process:exec(
    $cmd as xs:string,
    $args as xs:string*
) as element(process:result) external

Executes the specified string command in a separate process. Each of the strings in the sequence passed in as the second argument is passed as an argument to the executed command.

Parameters

  • $cmd

    command to be executed (without arguments)

  • $args

    the arguments passed to the executed command (e.g. "-la")

Returns

  • element(process:result)

    the result of the execution as an element as shown in the documentation of this module. The exit-code element returns the exit code of the child process. For POSIX compliant platforms: returns the process exit code. If process is terminated or stopped: 128 + termination signal code. For Windows platforms: returns the return value of the process or the exit or terminate process specified value.

Errors

  • process:PROC01

    if an error occurred while communicating with the executed process.