0

In my application I run an external MapInfo Program. In general it works fine, but I get an error and I have no idea how to solve it.

const util = require('util');
const execFile = util.promisify(require('child_process').execFile);
const mbxs = ['DPImapObjCellDir.MBX', 'DPImapObjAdditional.MBX'];

await Promise.all(
   mbxs.map(x =>
      execFile(
         config.MapInfo.bin,
         ['-server', path.join(config.MapInfo.mbx !== undefined ? config.MapInfo.mbx : __dirname, x)],
         {
            windowsHide: true,
            env: Object.assign(process.env,
               {
                  NLS_LANG: "AMERICAN_SWITZERLAND.WE8MSWIN1252",
                  DPI_INI: path.resolve(process.argv[2])
               })
         },
         error => { if (error) console.error(error.stack) }
      ).catch(e => console.error(e.stack))
   )
);


Error: Command failed: c:\Programs\MapInfo Professional\MapInfo_12.5\MapInfow.exe -server c:\Developing\Source\DPI\Server\Generator\MapInfo\bin\DPImapObjAdditional.MBX

    at ChildProcess.exithandler (node:child_process:397:12)
    at ChildProcess.emit (node:events:390:28)
    at maybeClose (node:internal/child_process:1062:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
    at Process.callbackTrampoline (node:internal/async_hooks:130:17) {
  killed: false,
  code: 3221226525,
  signal: null,
  cmd: 'c:\\Programs\\MapInfo Professional\\MapInfo_12.5\\MapInfow.exe -server c:\\Developing\\Source\\DPI\\Server\\Generator\\MapInfo\\bin\\DPImapObjAdditional.MBX'
}

According the logs in MapInfo itself, the program finished without any error. So I have no idea why Node considers the program as failed.

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110

1 Answers1

0

In the end, I used workaround like this:

await Promise.all(
   mbx.map(x =>
      execFile(
         config.MapInfo.bin,
         ['-server', path.join(config.MapInfo.mbx !== undefined ? config.MapInfo.mbx : __dirname, x.bin)],
         {
            windowsHide: true,
            env: Object.assign(process.env,
               {
                  NLS_LANG: "AMERICAN_SWITZERLAND.WE8MSWIN1252",
                  DPI_INI: path.resolve(process.argv[2]),
                  DPI_CELL_DIR: x.DPI_CELL_DIR
               })
         }
      ).catch((error) => { if (error && error.code != 3221226525) logger.error(error.stack) })
   )
);

The execFile() method must not give any callback function, otherwise the script exits after the Promise.

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110