0

在我的应用程序中,我运行了一个外部 MapInfo 程序。一般来说它工作正常,但我得到一个错误,我不知道如何解决它。

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'
}

根据 MapInfo 本身的日志,程序完成没有任何错误。所以我不知道为什么 Node 认为程序失败了。

4

1 回答 1

0

最后,我使用了这样的解决方法:

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) })
   )
);

execFile()方法不能给出任何callback函数,否则脚本在 Promise 后退出。

于 2021-12-07T11:09:59.660 回答