3 Replies Latest reply on Apr 28, 2014 12:32 AM by Patook2132

    HTML extension CEPEngine process stdout and stderr usage

    Patook2132

      Hi all,

       

      I'm trying to use CEPEngine to start a ncftpput process on windows.

      I need to listen what ncftpput output on stdout to make a sort of progress bar.

       

      Unfortunatly cep.process.stdout callback seems to receive only the first line of output (LibNcFTP 3.2.5 (January 17, 2011) compiled for Windows)

       

      This is my code :

       

                  var exe=extpath+"\\resources\\win\\ncftpput.exe";
                  var result=cep.process.createProcess(exe,"-Z","-d","stdout","-P",port,"-R",ip,"/",filepath);
                  if (result.err==cep.fs.NO_ERROR) {
                      var pid = result.data;
                      cep.process.stdout(pid,function(e){
                          console.log(e);//receive only the first line in stdout ?
                      });
                      cep.process.stderr(pid,function(e){
                          console.log(e); //receive nothing ?
                      });
                      cep.process.onquit(pid,function(){
                          console.log("quit");
                      });
                  }
      

       

       

      Is it a known bug or there's something I'm doing wrong ?

       

      (That kind of thing worked with previous AS extensions)

        • 1. Re: HTML extension CEPEngine process stdout and stderr usage
          weiguo@adobe.com Adobe Employee

          Limitation of cep.process.stdout/stderr

          There is an known limitation of cep.process.stdout/stderr which is targeting to capture one time of stdout/stderr output.

          For applications that has not integrated CEP 5, there are two workarounds are suggested as the following.

          1. 1. Embed cep.process.stdout/stderr, like below
          2. window.cep.process.stdout(proc.data,function(line){

              console.log(line);

              window.cep.process.stdout(proc.data,function(line2){

                  console.log(line2); 

                  window.cep.process.stdout(proc.data,function(line3){

                      console.log(line3);

                  });

              });

          });

          1. 2. Join all stdout output as one, like below

          var str1 = 'abcdef';

          var str2 = '12345';

          var str3 = 'gghhtt';

          1. console.log(str1 + str2 + str3);

          Since CEP5, NodeJS is integrated into CEP runtime and users could invoke the standard APIs of NodeJS in extension directly. For applications that has integrated CEP 5, refer to http://nodejs.org/api/process.html for how to use the global process object in NodeJS.

          • 2. Re: HTML extension CEPEngine process stdout and stderr usage
            jun xia Adobe Employee

            Hi,

             

            Yes, like Guo said, there is a limitation of window.cep.process.stdout/stderr. But you could call it recursively like below to get all the stdout.

             

            function getSTDOutput()
                {
                    console.log("getSTDOutput");
                    window.cep.process.stdout(pid, function(output) {
                                                console.log(output);
                                                //your code is here
                                              });
                    var result = window.cep.process.isRunning(pid);
                    if (result.data == true)
                    {
                        setTimeout(getSTDOutput, 1000);
                    }
                }
            

            Could you have a try and let us know if this resolve your issue?

             

            Thanks,

            Jun

            • 3. Re: HTML extension CEPEngine process stdout and stderr usage
              Patook2132 Level 1

              Yes, it works, thanks for your responses !

               

              I made some litlle change from xia solution because i need to parse all lines individually :

               

                  function getSTDOutput(pid){
                      cep.process.stdout(pid, function(output) {
                          var lines=output.split(('\n'));
                          for (var i=0;i<lines.length;i++){
                              console.log(lines[i]);
                          }
                          var result = cep.process.isRunning(pid);
                          if (result.data == true){
                              setTimeout(function(){getSTDOutput(pid)}, 0);
                          }
                      });
                  }
              

               

              I can go further in my indesign extension migration