简体   繁体   中英

Python script works alone but no such file when run through nodejs child process

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

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

is the error i'm having trouble with, this command works fine from the python script but not through a childprocess spawn, downloads and the .py script are in the same folder, and both of them are in a folder next to the nodejs script

this is the method that i call from a post function to give it the imagine fine that i need to transcribe, then the python script can't run the tesseract command, even though it can do it when its run manually

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM