从终端运行不会产生与从调试运行相同的结果

时间:2018-10-09 09:47:31

标签: javascript node.js tesseract

我有以下代码

    var Tesseract = require('tesseract.js')
    var filename = '2.jpg'

    Tesseract.recognize(filename)
    .progress(function  (p) { console.log('progress', p)  })
    .catch(err => console.error(err))
    .then(function (result) {
    console.log(result.text)
    //getPersonName(result.text);
    process.exit();
  })

使用命令节点ocr.js运行时,一切运行正常,我从图片中获取了文字

但是,如果我使用节点调试器从Visual Studio代码调试运行,则会收到以下错误:

C:\Program Files\nodejs\node.exe --inspect-brk=19996 ocr.js 
Debugger listening on ws://127.0.0.1:19996/21ca94e0-ff75-4386-8b0c-ce8342aad6af
Starting inspector on 127.0.0.1:19996 failed: address already in use
Debugger attached.
events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at _errnoException (util.js:1022:11)
    at ChildProcess.target._send (internal/child_process.js:702:20)
    at ChildProcess.target.send (internal/child_process.js:586:19)
    at c:\Users\jorgem\Desktop\ocrjs2\node_modules\tesseract.js\src\node\index.js:28:25
    at loadImage (c:\Users\jorgem\Desktop\ocrjs2\node_modules\tesseract.js\src\node\index.js:96:5)
    at loadImage (c:\Users\jorgem\Desktop\ocrjs2\node_modules\tesseract.js\src\node\index.js:94:16)
at c:\Users\jorgem\Desktop\ocrjs2\node_modules\tesseract.js\src\node\index.js:48:13
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)
Waiting for the debugger to disconnect...
Error: write EPIPE
util.js:1022
    at _errnoException (util.js:1022:11)
    at ChildProcess.target._send (internal/child_process.js:702:20)
    at ChildProcess.target.send (internal/child_process.js:586:19)
    at c:\Users\jorgem\Desktop\ocrjs2\node_modules\tesseract.js\src\node\index.js:28:25
    at loadImage (c:\Users\jorgem\Desktop\ocrjs2\node_modules\tesseract.js\src\node\index.js:96:5)
    at loadImage (c:\Users\jorgem\Desktop\ocrjs2\node_modules\tesseract.js\src\node\index.js:94:16)
    at loadImage (c:\Users\jorgem\Desktop\ocrjs2\node_modules\tesseract.js\src\node\index.js:83:13)
    at c:\Users\jorgem\Desktop\ocrjs2\node_modules\tesseract.js\src\node\index.js:48:13
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)

我做错了什么?

我的launch.json文件如下所示:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}/ocr.js"
        }
    ]
}

1 个答案:

答案 0 :(得分:2)

问题已解决:我们在launch.json文件中添加了两行:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",                ,
            **"port": 5859,
            "timeout": 30000,**
            "program": "${workspaceFolder}/ocr.js"
        }
    ]
}

这解决了问题