0

I have two Java scripts and i would like to merge them to get a output that can be treated as successful or failure. I'm not sure if this is the right direction or if i have got this completely wrong.

Initial script is to git clone the repos

const shell = require('shelljs')
const path = '/home/test/'
shell.cd(path)
shell.exec('git clone https://github.com/test/mic.git')

This is a java script and it does clone the repo. node git.js and it simply clones the repos

Now I have another script which needs to get the result of the above script and pass it to a variable which then says if it is success of failure.

var body = response.getResponseBody();
var res = JSON.parse(body);

if (res.flag < 1){
    api.setValue("flag", "failed");
}

Is there a way to integrate these scripts to get the right results. All i want is if the first script will success/fail and get the status as a result which can be passed as a flag to another variable.

Any directions is really helpful

anish anil
  • 2,299
  • 7
  • 21
  • 41

1 Answers1

1

Shell.exec takes a callback. If you have an error the code parameter in the callback should be a non-zero

shell.exec('git clone https://github.com/test/mic.git', (code, stdout, stderr) => {
    if(code === 0) {
     // No Error 
    } else {
     // Had an error
    }
})
jeeves
  • 1,871
  • 9
  • 25