3

I am newbie to node.js. I have created a child process in node.js to connect it with my Java program. I used eclipse to create an executable jar file(Saxon.jar). This is my app.js(JavaScript) file.

var fs = require('fs');

var exec = require('child_process').exec;
var child = exec('java -jar Saxon.jar',
  function (error, stdout, stderr){
    console.log('stdout: ' + stdout);
    console.log('stderr: ' + stderr);
    if(error !== null){
      console.log('exec error: ' + error);
    }
});

module.exports = child;

My Java program is converting xml into html webpage using xslt stylesheet. Right now, I am getting my result in command prompt. The result looks like this:

https://i.sstatic.net/2yTIY.png

I want my output to write in a HTML file.

1 Answer 1

1

You can just use fs.writeFile to write stdout to the file then:

var fs = require('fs');
var pathToFile = 'path/to/file.html';

var exec = require('child_process').exec;
var child = exec('java -jar Saxon.jar', function (error, stdout, stderr){
    fs.writeFile(pathToFile, stdout, function(err) {
       if(err) console.error(err);
    })
});

module.exports = child;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. It worked. Now I am getting my output as html web page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.