Saxon9 (old version): Java Runtime Exec in XSL don't generate value - xslt

I'm using the Saxon9 old version to use the java runtime exec to execute a ruby script, this is the first time I'm trying out a runtime exec. I used the below code to run a ruby script it's not producing any results to value.
Due to a limitation, I'm unable to use the SaxonEE or Saxon PE so I'm trying to use the old version.
<xsl:variable name="javatest" select="runtime:exec(runtime:getRuntime(), 'ruby test.rb')" />
<xsl:variable name="waiting" select ="process:waitFor($javatest)" />
<xsl:value-of select="$javatest" />
The above code is not producing an actual result from the ruby script, It always generates results like java.lang.ProcessImpl#170c109. Is this achievable in saxon9?

Firstly, the value of variable $javatest is going to be a wrapper object around the result of calling java.lang.RunTime.exec(), which is an instance of java.lang.Process, and that's exactly what you're seeing. If you want to get the output of that process, you probably need to call its getOutputStream() method. It's probably all going to be easier if you write a utility method in Java that calls the exec() method, gets the output stream, and returns the contents of the output stream as a string.
Second point: the variable $waiting is declared but never used, so it's never going to be evaluated. Don't try to call external methods like this for the sake of their side-effects. Best to include the waitFor() call in your Java utility method; but if you want to do it all from XSLT, use the integer result of the method somehow, for example do
<xsl:if test="$waiting ne 0">
<xsl:message terminate="yes">External process failed</xsl:message>
</xsl:if>

Related

Output of additional files (detectors, induction loops) are not being generated

Output of additional files (detectors, induction loops) are not being generated. I used a simple scenario, just to see how things work. But I cannot see or maybe these files are not being generated. I added them at launch.xml and sumo.cfg as additional files. This is the code for detector.xml :
<additional>
<laneAreaDetector id="E2" lane="1to2_0" pos="15" endPos="20" length="20.0" friendlyPos="false" freq="5.890e9" file="ostie.xml" timeThreshold="1" speedThreshold="3.6" jamThreshold="10.0" />
</additional>
<additional>
<inductionLoop id="myLoop1" lane="1to2_0" pos="16.0" freq="900" file="out.xml" />
<inductionLoop id="myLoop2" lane="1to2_0" pos="100.0" freq="900" file="out.xml" />
</additional>
The file out is empty. Please help!
Thanks in advance.
You might be using sumo-launchd.py of Veins to run your simulation. If so, the SUMO simulation will execute in a temporary directory (that is, by default, deleted after the simulation concludes). You will either turn this off (see the output of --help) or create the output files in another directory to retain them.

c++ software passing arguments method

I have a problem related to passing arguments to a C++ compiled executable. The program emulate the behaviour of a particular inference engine: the setup of the engine is load at runtime from an XML file, and then I want to call it from command line with different input values.
The characteristic of the input are:
Every time that I call the program, the input structure is different, because the system itself is different.
The input is a set of couple {name, value}, one for each part of the system.
I have to separate the configuration XML from the input.
I call the program from a PHP or Node.js server, since it return a result that I expose to the outside through an API.
Input value are obtained from an HTTP post request.
By now I have tried these solutions:
Pass it from the command line ex: "./mysoftware input1 value1 input2 value2 ...etc". A little unconfortable, since I have up to 200 input.
Create a file with all the couples name,value and then call the program that parse the file and then destroy at the end. This is a bottleneck of performance for my API, because at every call I have to create and destruct a file.
Does anyone know a better way to approach this problem?
3. Pass the values to the program via the standard input stream and read them from std::cin inside your C++ program.

exslt distinct() does not work with xalan compiled (but works in interpreted)

I have this:
<xsl:message><xsl:copy-of select="set:distinct(//property)"/> </xsl:message>
<!--<xsl:message><xsl:copy-of select="set:distinct(common:node-set($mss)/indirect)"/> </xsl:message>-->
If I uncomment the second line, it does not work1 when I use the stylesheet with compiled stylesheet in xalan.
It does work when I run xalan from the command line without -xsltc.
Am I doing something wrong?
1 I get some cryptic error message, and processing stops. Here is the error message for this instance: ERROR: '', but I got things like ERROR: -1 as well.
My <xsl:stylesheet> header contains xmlns:set="http://exslt.org/sets".

CFExecute not performing command

<cfset LOCAL.cmd = expandPath('..\library\gm.exe') />
<cfset LOCAL.args = "convert image1.jpg image2.jpg" />
<cfexecute variable="gm" errorVariable="error"
name="#LOCAL.cmd#"
timeout="10"
arguments="#local.args#" />
<cfdump var="#gm#" />
This code always results in an empty string in gm. No matter how I execute gm with or without parameters. Other examples work fine like running cmd.exe or netstat.exe as is in the CFDocs example. I get no errors thrown or warnings in errorVariable, it simply does nothing.
I modified the code, this version does not work either:
<cfset LOCAL.cmd = expandPath('..\library\gm.exe') />
<cfset LOCAL.args = "convert ""#variables.uploadDirectory##LOCAL.file.source#"" ""#variables.uploadDirectory#optimal-#LOCAL.file.source#""" />
<cfexecute errorVariable="error"
name="c:\windows\system32\cmd.exe"
timeout="10"
outputFile="#expandPath('.\gm.log')#"
arguments="/C #local.cmd# #LOCAL.args#" />
Permissions problems are the most common cause. However, if you are running CF8, you might also try redirecting the error stream and adding an explicit terminate flag. Just to see if you get any output or see different behavior. Early versions did not capture the error stream, which caused some processes to hang. It was fixed in one of the CF8 updaters.
Update: I just noticed your image paths are relative. Perhaps the program is having difficulty locating them. Try using absolute paths for the images.
Update: I tested it with CF9. It does work when using absolute image paths. Though the "gm" variable is understandably empty, since the output is directed to an image file.
<cfexecute variable="gm"
errorVariable="errorOut"
name="C:\GraphicsMagick-1.3.12-Q16\gm.exe"
timeout="10"
arguments="convert c:\art.gif c:\artCopyFromCF9.gif" />
<cfdump var="#variables#">
Without seeing code or your server setup, I would guess you need to check permissions for the user account CF runs under.
If CF is running under the default user, you may need to create a user with access to whatever it is you are trying to do. Then change the service(s) to run under this user. Alternately, you could assign more liberal permissions to the resource you're trying to access.
I have also encountered this with cfexecute and GraphicsMagick. I think the deal is that GM is operating asynchronously and returns before it completes. Running some tests with outputFile/errorFile instead of their variable equivalents, followed by cffile reading the fileInfo on the output file (which is empty per the test script but observed to have contents when opened), I see that the modified time of the output file with contents is actually after the last modified timestamp yielded by FileInfo.
I think if you output to a session variable or something of the sort that could be picked up by another template you could observe the results of the execution having populated the session variable, provided the other template executes after the variable is actually set.

Calling Lua function without executing script

I am embedding Lua into a C/C++ application. Is there any way to call a Lua function from C/C++ without executing the entire script first?
I've tried doing this:
//call lua script from C/C++ program
luaL_loadfile(L,"hello.lua");
//call lua function from C/C++ program
lua_getglobal(L,"bar");
lua_call(L,0,0);
But it gives me this:
PANIC: unprotected error in call to Lua API (attempt to call a nil value)
I can only call bar() when I do this:
//call lua script from C/C++ program
luaL_dofile(L,"hello.lua"); //this executes the script once, which I don't like
//call lua function from C/C++ program
lua_getglobal(L,"bar");
lua_call(L,0,0);
But it gives me this:
hello
stackoverflow!!
I am wanting this:
stackoverflow!
This is my lua script:
print("hello");
function bar()
print("stackoverflow!");
end
As was just discussed in #lua on freenode luaL_loadfile simply compiles the file into a callable chunk, at that point none of the code inside the file has run (which includes the function definitions), as such in order to get the definition of bar to execute the chunk must be called (which is what luaL_dofile does).
Found out that the script must be run to call the function.
One possible solution / hack (and please bear in mind that I'm currently unable to test this)...
Insert a dummy "return;" line at the top of your LUA code.
Load your file into a string (like you would in preparation for using luaL_loadstring())
Now it should be a simple matter of using printf_s("return;\r\n%s", [pointer to string holding actual LUA code])
Now you can luaL_loadstring() the concatenated string
The code will still execute, but it should get cut off before it can actually reach anything that does something (in your print("hello"); example, the print line would become unreachable). It should still have updated the list of all the function prototypes and you should now be able to use lua_get() to reference the functions.
NOTE: For those who don't know "\r\n" are the escape codes representing a newline on the Windows OS, and it MUST be those slashes...   IE: THIS \r\n       NOT THIS /r/n