This program will not terminate in the console, I have to use Ctrl-C. Documentation does not give any clues. Tried various things such as Return but just can't get it to terminate, it just hangs in the console. The last thing in the console is 'now we are here'.
var fs = require('fs');
var path = require('path');
var co = require('co');
var prompt = require('co-prompt');
var program = require('commander');
program
.arguments('<file>')
.option('-i, --Object name <objectName>', 'DP device IP address')
.action(function(file) {
co(function *() {
var objectName = yield prompt('Object Name: ');
console.log('\nObject Name: %s file: %s',objectName, file);
notmain(file, objectName);
console.info('now we are here');
});
})
.parse(process.argv);
function notmain(file, objectName) {
try {
var normalPath = path.normalize(__dirname + '/' + file);
console.info('\nfile path ' + normalPath);
certstring = fs.readFileSync(normalPath).toString();
console.info('\nstring of cert file is \n' + certstring);
clientcert = fs.readFileSync(normalPath).toString('base64');
console.info('\nbase64 string of cert file is \n' + clientcert);
var newJson = {};
newJson.name = objectName;
newJson.content = clientcert;
var newfile = {"file": newJson};
console.info('\nnew json for cert object ' + JSON.stringify(newfile));
console.info('\nclient certificate read from directory ');
} catch (err) {
console.info('file path ' + normalPath);
console.info('client certificate file not found');
return;
}
}
The console is waiting on more input. Try adding this after the 'now we are here' line.
process.stdin.pause();
like this
co(function *() {
var objectName = yield prompt('Object Name: ');
console.log('\nObject Name: %s file: %s',objectName, file);
notmain(file, objectName);
console.info('now we are here');
process.stdin.pause();
});