Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to capture output of getruntime in java, despite it working perfectly outside
    primarykey
    data
    text
    <p>So here's the deal: I have a node.js script that queries a mysql database of my own. Simple select, nothing much. If I run it from the command line I get my expected results without problem.(see below)</p> <p>However, when I run said script from java using the code below for it to save the results in an array for later use, what happens is that those arrays will always be empty. Even a straight prints show nothing.</p> <pre><code>public static ArrayList&lt;String&gt; scriptcaller(String command){ ArrayList&lt;String&gt; out = new ArrayList&lt;String&gt;(); ArrayList&lt;String&gt; errors = new ArrayList&lt;String&gt;(); BufferedReader bri, bre; try { String line; Process p = Runtime.getRuntime().exec(command); bri = new BufferedReader (new InputStreamReader(p.getInputStream())); bre = new BufferedReader (new InputStreamReader(p.getErrorStream())); //guardar linhas de outpur em out while ((line = bri.readLine()) != null) { System.out.println(line); out.add(line); } bri.close(); //guardar linhas de errors em errors while ((line = bre.readLine()) !=null) { //System.out.println(line); errors.add(line); } bre.close(); p.waitFor(); System.out.println("Done."); } catch (Exception err) { err.printStackTrace(); } return out; } </code></pre> <p>The output of the script is something like this when executed straight in from the command line: </p> <pre><code>[{userID: mryuur, type: 'energy', value: '1337'}] </code></pre> <p>I have used the java function with other scripts and commands and it worked fine.</p> <p>Here is part of the query script:</p> <pre><code>var userparam = "mryuur"; var querybody = 'SELECT * FROM GAP WHERE userID = "'+userparam+'"'; var query = connection.query(querybody, function(err, result) { if (err) { return console.log(err); } console.log(result); //console.log("Done"); process.exit(0); }); </code></pre> <p>Thanks in advance.</p> <p>EDIT I tried to run the following script on a similar java function that takes several parameters.</p> <p>(part of it)</p> <pre><code>var user, type, value, time; // print process.argv process.argv.forEach(function (val, index, array) { console.log(index + ': ' + val); if (index == 2) {user = val} if (index == 3) {type = val} if (index == 4) {value = val} if (index == 5) {time = val} }); connection.connect(function(err) { // connected! (unless `err` is set) }); var insertbody = 'INSERT INTO GAP(`userID`, `type`, `value`, `timestp`) VALUES ("'+user+'","'+type+'","'+value+'","'+time+'")' var query = connection.query(insertbody, function(err, result) { if (err) { return console.log(err); } console.log(result); //console.log("Done"); process.exit(0); }); </code></pre> <p>what happened was that the console.log where i print the parameters passed, for testing purposes, did show up in the java console but the console.log(result) to print the result of the insert did not. Note that both show accordingly when the script is executed straight from the command line.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload