1

For a project structure like this:

/myfolder/app/components/owl2vowl.jar
/myfolder/app/uploads/ontology.owl
/myfolder/app.js

I am using OWL2VOWL to convert an ontology into a JSON

I wrote code in app.js to run the jar file with some parameters, which will run the command like this:

java -jar e:\myfolder\app\components\owl2vowl.jar -file e:\myfolder\app\uploads\ontology.owl 

Here is the code:

var exec = require('child_process').exec, child;
child = exec('java -jar ' +  __dirname + '/components/owl2vowl.jar' + ' -file ' + syncPath ,
function (error, stdout, stderr){
  if(error !== null)
    console.log('There was an error parsing the ontology' + error);
  else           
    console.log('Succes parsing the ontology');

where

syncPath = e:\myfolder\app\uploads\ontology.owl 

The problem is that the result is generated in folder myfolder generating the file ontology.json

How can I change the path where the result of the Java file is generated? Ideally into \app\uploads ?

/myfolder/app/components/owl2vowl.jar
/myfolder/app/uploads/ontology.owl
/myfolder/app.js
/myfolder/ontology.json

Edit - Added solution

the solution a suggested by javabeangrinder is to add a cwd option (in the following, the result will be outputted in the folder /components )

var options = { encoding: 'utf8',
                              timeout: 0,
                              maxBuffer: 200*1024,
                              killSignal: 'SIGTERM',
                              cwd:  __dirname + '/components/',
                              env: null }

child = exec('java -jar ' +  __dirname + '/components/owl2vowl.jar' + ' -iri ' + '"'+body.url+'"'+'  -echo' , options,
                              function (error, stdout, stderr){})
3
  • Why not move the file with NodeJS fs.rename(oldPath, newPath), after it is generated? Commented Aug 25, 2015 at 8:08
  • Already doing it - //move file from root to /cached/ fs.rename(getFileName.split(".")[0]+".json", __dirname + '/cached/' + getFileName.split(".")[0]+".json"); but the JAR can generate different file names (depending on the point in time when Java is called). Commented Aug 25, 2015 at 13:01
  • Your other option is to fork the OWL2VOWL project, add another commandline argument such as outputPath and implement the functionality. It shouldn't be a big deal, something like exportFile = new File(outputPath, filename) in github.com/VisualDataWeb/OWL2VOWL/blob/master/src/main/java/de/… Commented Aug 25, 2015 at 13:18

1 Answer 1

1

The problem is not the java code although it could be fixed changing it to accept an output folder as suggested earlier.

I believe that adding the node.js exec option cwd to the directory where you would like the output would do the trick.

Look further here: child_process.exec(command[, options], callback)

Sign up to request clarification or add additional context in comments.

Comments

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.