简体   繁体   English

在node.js中执行时,子进程突然退出

[英]Child Process exits abruptly while executing in node.js

So I have been working on a project and it requires me to convert the office files into PDFs and subsequently images. 因此,我一直在从事一个项目,这需要我将Office文件转换为PDF,然后转换为图像。 I've written and integrated everything into one single node.js script, but for some reason the script keeps on bypassing the synchronous child process creation. 我已经将所有内容编写并集成到一个单个的node.js脚本中,但是由于某种原因,该脚本一直绕过同步子进程的创建。 Here is the code: 这是代码:

    down.download(parsed_url);
            var f_name=obj.doc;
            var ext=f_name.slice(f_name.length-4);
            var w_path="C:\\Users\\Akshay\\Desktop\\conv_Scripts\\word_pdf.ps1";
            var e_path="C:\\Users\\Akshay\\Desktop\\conv_Scripts\\excel_pdf.ps1";
            var p_path="C:\\Users\\Akshay\\Desktop\\conv_Scripts\\power_pdf.ps1";
            var file_name=f_name.slice(0,f_name.length-5);
           console.log(ext);
           console.log(f_name);
           console.log(file_name);

            if(ext==="docx"){
             word.wordpdf(w_path);           

            } 

        else if(ext==="xlsx"){
         excel.excelpdf(e_path);}
        else if(ext==="pptx"){
         ppt.pptpdf(p_path);
         console.log("Done converting to PD");
        }
        else if(ext==".pdf"){
         img.img(f_name);

        }
    else{
     console.log("Can't convert to PDF");
    }

crawlpdf.crawlpdf(file_name,function(collect){
 collect.forEach(function(col){
   img.img(col);
   console.log('Done!');


 });

the wordpdf,excelpdf and pptpdf functions are same in their structure. wordpdf,excelpdf和pptpdf函数的结构相同。 I'll write down the wordpdf module's code here: 我将在此处写下wordpdf模块的代码:

var spawn=require('child_process').spawnSync,
    child;

exports.wordpdf=function(filepath){
    child=spawn("powershell.exe",[filepath]);


};

The trouble is that when I execute the script,it shows me "Done converting to PD" (since the downloaded file was a ppt) but I do not find any pdf of the downloaded file .The .ps1 scripts in the path are already tested and there is no issue with them. 问题是执行脚本时,它显示“已完成转换为PD”(因为下载的文件是ppt),但是找不到下载的文件的pdf。路径中的.ps1脚本已经过测试他们没有问题。 If you could shed some light it would be really a massive help to me. 如果您能找到一些启示,那对我来说确实是巨大的帮助。

Thanks. 谢谢。

Alright, In case anyone else runs into the same issue as this, here's the explanation for what went wrong: 好吧,万一其他人遇到了同样的问题,以下是发生问题的解释:

The message coming from the RabbitMQ messsage queue is small.Hence when the message arrives it is rapidly consumed,leading to race conditions in the code. 来自RabbitMQ消息队列的消息很小。因此,消息到达后,消息将被快速消耗,从而导致代码中出现争用情况。 For better and more accurate performance try parsing and writing the message to a file and then use async module to do the necessary steps. 为了获得更好,更准确的性能,请尝试将消息解析并将其写入文件,然后使用异步模块执行必要的步骤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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