首页 > 解决方案 > Python脚本单独工作,但通过nodejs子进程运行时没有这样的文件

问题描述

Error, could not create TXT output file: No such file or directory

tesseract ./downloads/en.jpg outputs/1585336201.287781output -l eng

是我遇到问题的错误,此命令在 python 脚本中运行良好,但不能通过子进程生成,下载和 .py 脚本位于同一文件夹中,并且它们都位于 nodejs 脚本旁边的文件夹中

这是我从 post 函数调用的方法,给它我需要转录的想象,然后 python 脚本无法运行 tesseract 命令,即使它可以在手动运行时执行

const verif = async (fileName, filePath) => {

    var uint8arrayToString = function(data){
        return String.fromCharCode.apply(null, data);
    };

    const spawn = require('child_process').spawn;

    const scriptExecution = spawn('python',['-u', './diploma/app.py']);

    var data = JSON.stringify([fileName]);
    scriptExecution.stdin.write(data);
    scriptExecution.stdin.end();

    scriptExecution.stdout.on('data', (data) => {
        console.log(uint8arrayToString(data));
    });

    scriptExecution.stderr.on('data', (data) => {
        // As said before, convert the Uint8Array to a readable string.
        console.log(uint8arrayToString(data));
    });

    scriptExecution.on('exit', (code) => {
        console.log("Process quit with code : " + code);
    });
    return true;
}

标签: pythonnode.jschild-process

解决方案


问题是tesseract从js文件执行时需要windows权限


推荐阅读