Changes

Jump to navigation Jump to search
648 bytes added ,  16:19, 27 February 2020
no edit summary
=Conventions=
 
{{Mark|Updated with Version 9.0}}:
All functions and errors in this module are assigned to the <code><nowiki>http://basex.org/modules/proc</nowiki></code> namespace, which is statically bound to the {{Code|proc}} prefix.<br/>
* {{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):<syntaxhighlight lang="xquery">proc:system( 'wc', (), map { 'input': 'A B' || out:nl() || 'C' })</syntaxhighlight>* 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 classsyntaxhighlight lang="brush:xquery">
try {
proc:system('xyz')
} catch bxerrproc:BXPR0002 error { 'Command not found.: '|| $err:description
}
</presyntaxhighlight>
|}
|-
| '''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 classsyntaxhighlight lang="brush:xml">
<result>
<output>...result output...</output> <error>...error outputmessage...</error> <code>0...process code...</code>
</result>
</presyntaxhighlight>
|-
|'''Errors'''
==proc:fork==
 
{{Mark|Introduced with Version 9.0:}}
{| width='100%'
| '''Examples'''
|
* {{Code|proc:property('java.class.path')}} returns the full user class path.
* {{Code|map:merge(proc:property-names() ! map:entry(., proc:property(.)))}} returns a map with all system properties.
|}
=Errors=
 
{{Mark|Updated with Version 9.0}}:
{| class="wikitable" width="100%"
* Added: [[#proc:fork|proc:fork]]
* Updated: error codes updates; 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