partridgejiang / Kekule.js

A Javascript cheminformatics toolkit.
http://partridgejiang.github.io/Kekule.js
MIT License
248 stars 61 forks source link

openbabel warning #233

Open niuzhenjiang opened 3 years ago

niuzhenjiang commented 3 years ago

sorry to ask you some weird question... i use openbabel.js for smiles import plugin.but my smiles have some error ,can't generate. i want to know how can i catch this warning to tell user smiles have some error. image

partridgejiang commented 3 years ago

You can do some hacks to redirect the stdout/stderr output of the OpenBabel module:

var EU = Kekule.EmscriptenUtils;
EU.getRootModule = function(moduleName, creationOptions)
{
  var result = EU._createdModules[moduleName];
  if (!result)
  {
    var m = EU._getActualModule(moduleName);
    result = m({
      'print': function(text) { console.log('[stdout]' + text); },  // redirect the stdout output
      'printErr': function(text) { console.log('[stderr]' + text); },  // redirect the stderr output
    });
    EU._createdModules[moduleName] = result;
  }
  return result;
}

Kekule.OpenBabel.enable();