Absent Member.
Absent Member.
377 views

Grabbing output from an xpath runtime script in null driver

Hi there,

We're running a script from the null driver. (Thanks to Steven Tharp!) This script produces a REST request, and I'm currently writing the response to a file. But I would like to get it to appear in the null driver trace. Is there any way to assign the script output to a variable you can write to the trace? I know the scripting driver is smarter about these things, and I am working in parallel to try to get that going, but (of course!) we're under a time crunch, and it is currently working with null. So... any ideas? and java junkies out there? I tried searching for xpath and runtime and saw some java.lang bits that looked like it would get the result (being, I assume, either zero - worked, or non-zero, didn't work), but that's not super helpful at this time.

Thanks for any advice -
Karla B
Labels (1)
0 Likes
3 Replies
Highlighted
Knowledge Partner
Knowledge Partner

Re: Grabbing output from an xpath runtime script in null driver

Anything called via Java should have the possibility to send output back
to java, so assuming a variable is assigned to it then capturing it should
be possible.

Without seeing how the call is made, and if the script even generates
output, that's all i can provide other than generic Java docs which may
match what you are doing:

https://stackoverflow.com/questions/1410741/how-to-invoke-a-linux-shell-command-from-java
#how to call a function from Java, which I presume will look similar to
your XPath stuff

https://docs.oracle.com/javase/8/docs/api/java/lang/Process.html #see the
getOutputStream() method to get the object that will then have your
standard output (STDOUT) data. There is also one for standard error.

In your case if your script is writing to a file and NOT to STDOUT, then
you'd probably just need to have some other xpath command read that file
and get its contents to then be traced. There is a tracer ECMAscript
method that you should be able to use once you have the data in the engine
somewhere (vs. in a filesystem).

--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below.

If you want to send me a private message, please let me know in the
forum as I do not use the web interface often.
0 Likes
Highlighted
Knowledge Partner
Knowledge Partner

Re: Grabbing output from an xpath runtime script in null driver

kborecky wrote:

> We're running a script from the null driver.


What kind of script and how do you run it? If it's an ECMA called from xpath
you can trace directly by calling:

var tracer = new Packages.com.novell.nds.dirxml.driver.Trace("myEcmaScript");
tracer.trace(message, level);

--
http://www.is4it.de/en/solution/identity-access-management/

(If you find this post helpful, please click on the star below.)
______________________________________________
https://www.is4it.de/identity-access-management
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Grabbing output from an xpath runtime script in null dri

Thanks, everyone! Aaron found the solution. After you define your command line string, you use "execString" to grab the output (before you actually run the command, of course.) This will get whatever output the script produces (echo, print, etc.)

Steps:

1. Add the necessary namespaces:

<namespace-def name="es" value="http://www.novell.com/nxsl/ecmascript"/>
<namespace-def name="js" value="http://www.novell.com/nxsl/ecmascript"/>
<namespace-def name="cmd" value="http://www.novell.com/nxsl/java/com.novell.nds.dirxml.driver.XdsCommandProcessor"/>
<namespace-def name="runtime" value="http://www.novell.com/nxsl/java/java.lang.Runtime"/>

or, using the Edit Namespaces wizard:

[table="width: 250"]

Prefix
URI
Java ext?

[tr]
es
http://www.novell.com/nxsl/ecmascript
[td][/td]
[/tr]
[tr]
js
http://www.novell.com/nxsl/ecmascript
[td][/td]
[/tr]

cmd
com.novell.nds.dirxml.driver.XdsCommandProcessor
yes



runtime
java.lang.Runtime
yes


[/table]

2. Define local variables to establish the runtime instance and the command line you want to run.

Runtime instance:

<do-set-local-variable name="runtime-instance" scope="policy">
[INDENT] <arg-object>
[/INDENT] [INDENT][INDENT]<token-xpath expression="runtime:getRuntime()"/>[/INDENT][/INDENT]
[INDENT]</arg-object>[/INDENT]
</do-set-local-variable>

Command line:

<do-set-local-variable name="cmdLine" scope="policy">
[INDENT]<arg-string>[/INDENT]
[INDENT][INDENT]<token-text xml:space="preserve">/your/path/here/myscript.sh</token-text>[/INDENT][/INDENT]
[INDENT][INDENT][INDENT]<token-text xml:space="preserve"> </token-text>[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]<token-attr name="workforceID"/>[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]<token-text xml:space="preserve"> </token-text>[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]<token-attr name="CN"/>[/INDENT][/INDENT][/INDENT]
[INDENT]</arg-string>[/INDENT]
</do-set-local-variable>

This example defines this command line (with arguments) "/your/path/here/myscript.sh workforceID CN" Don't forget to add the spaces between arguments, if you're using them.

If you want, you can echo the resulting command line back to the trace file:

<do-trace-message>
[INDENT]<arg-string>[/INDENT]
[INDENT][INDENT]<token-local-variable name="cmdLine"/>[/INDENT][/INDENT]
[INDENT]</arg-string>[/INDENT]
</do-trace-message>

3. Define the local variable that prepares to grab the output of the command:

<do-set-local-variable name="result" scope="policy">
[INDENT]<arg-string>[/INDENT]
[INDENT][INDENT]<token-xpath expression="es:execString($cmdLine)"/>[/INDENT][/INDENT]
[INDENT]</arg-string>[/INDENT]
</do-set-local-variable>

Note the use of the command line variable defined in step 2.

4. Define a local variable that uses the runtime:exec command to execute the script:

<do-set-local-variable name="process" scope="policy">
[INDENT]<arg-object>[/INDENT]
[INDENT][INDENT]<token-xpath expression="runtime:exec($runtime-instance, $cmdLine)"/>[/INDENT][/INDENT]
[INDENT]</arg-object>[/INDENT]
</do-set-local-variable>

5. (Optional) Print the contents of the result variable to the trace file:

<do-trace-message level="1">
[INDENT]<arg-string>[/INDENT]
[INDENT][INDENT]<token-text xml:space="preserve">Results: </token-text>[/INDENT][/INDENT]
[INDENT][INDENT]<token-local-variable name="result"/>[/INDENT][/INDENT]
[INDENT]</arg-string>[/INDENT]
</do-trace-message>

I hope this helps someone else! Kudos to Aaron and Steven Tharp (for the original command line wizardry).
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.