简体   繁体   中英

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. 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. 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. I'll write down the wordpdf module's code here:

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. 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. 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.

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