fontoxpath icon indicating copy to clipboard operation
fontoxpath copied to clipboard

Please add `process:execute`

Open rrthomas opened this issue 2 years ago • 4 comments
trafficstars

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

as per https://en.wikibooks.org/wiki/XQuery/Execute_External_Process

This is not a standard function, of course, but this seems to be the commonest version of the function implemented in other systems.

rrthomas avatar Jul 15 '23 11:07 rrthomas

Hey Reuben,

Did you consider using an external function for this? Something like this should work:

registerCustomXPathFunction({namespaceURI: 'http://exist-db.org/xquery/process', localName: 'execute'}, ['xs:string', 'node()'], 'item()*', (_dynContext, command, options) => {
  // Do you magic here, something with child_process.execSync? https://nodejs.org/api/child_process.html#child_processexecsynccommand-options.
});

This way the NodeJS dependency also stays were it should be. FontoXPath is also running in the browser, where I don;t have access to shell commands.

Kind regards,

Martin

DrRataplan avatar Aug 14 '23 05:08 DrRataplan

Thanks, I'll try this. It would still be nice to have an implementation on platforms where it makes sense; I think this is not the only feature that doesn't make sense in the browser but does in other environments.

rrthomas avatar Aug 17 '23 11:08 rrthomas

Hey Reuben,

What kind of functions would those be? I'm not opposed to setting up an extension module to FontoXPath or something with those kinds of functions, to make FontoXPath easier to use in different environments. I'm now mainly working with the browser, but I guess some standard functions to access external information or maybe some of the [EXPath](expath.org] functions?

DrRataplan avatar Sep 07 '23 12:09 DrRataplan

Yes, your examples are exactly what I'm thinking of: accessing the file system, running processes, the sort of thing one wants to do in a server, command-line environment. The motivating case for my templating system Ruth, as linked above, is to be able to run arbitrary external commands.

rrthomas avatar Sep 07 '23 12:09 rrthomas