Changes

Jump to navigation Jump to search
717 bytes added ,  13:06, 18 January 2018
==proc:system==
 
{{Mark|Updated with Version 9.0:}} new {{Code|input}} option; revised error handling.
{| width='100%'
* {{Code|timeout}}: abort process execution after the specified number of seconds.
* {{Code|dir}}: process command in the specified directory.
* {{Code|input}}: standard string input ({{Code|stdin}}) to be passed on to the command.
|-
|'''Errors'''
|{{Error|encoding|#Error}} the specified encoding does not exist or is not supported.<br/>{{Error|timeout|#Error}} the specified timeout was exceeded.<br/>{{Error|error|#Error}} the command could not be executed, or an I/O exception was raised.<br/>{{Error|code....|#Error}} If the commands returns an exit code different to 0, an XQuery error will be raised. Its code will consist of the letters {{Code|code}} and four digits with the exit code. {{Code|code9999}} will be returned if the command cannot be executed.<br/>{{Error|encoding|#Error}} the specified encoding does not exist or is not supported.<br/>{{Error|timeout|#Error}} the specified timeout was exceeded.
|-
| '''Examples'''
|
* {{Code|proc:system('date')}} returns the current date on a Linux system.
* Analyses the given input and counts the number of lines, words and characters (provided that {{Code|wc}} is available on the system):<pre class="brush:xquery">proc:system( 'wc', (), map { 'input': 'A B' || out:nl() || 'C' })</pre>* The following example returns "Command “Command not found", if found” (unless {{Code|xyz}} is a valid command on the command "xyz" cannot be located or executedsystem):
<pre class="brush:xquery">
try {
proc:system('xyz')
} catch bxerrproc:BXPR0002 error { 'Command not found.: '|| $err:description
}
</pre>
|-
| '''Summary'''
|Executes the specified command in a separate process and returns the result as element. :* {{Code|$cmd}} is the name of the command, and arguments to the command may be specified via {{Code|$args}}. * The same {{Code|$options}} are allowed as for [[#proc:system|proc:system]]. The * Instead of the {{Code|proc:error}} error, the error message and process code will be assigned to the returned elements.* Instead of the {{Code|9999proc:code....}} error, the error message will be assigned if to the command cannot returned element (no process code will be executedreturned).<br/>A The result has the following structure:
<pre class="brush:xml">
<result>
<output>...result output...</output> <error>...error outputmessage...</error> <code>0...process code...</code>
</result>
</pre>
* Added: [[#proc:fork|proc:fork]]
* Updated: error codes updated; errors now use the module namespace* Updated: new {{Code|input}} option; revised error handling
;Version 8.6
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu