Skip navigation
Currently Being Moderated

NativeProcess progressevent doesn't get dispatched

Jul 6, 2012 3:38 AM

Tags: #nativeprocess #air_3.2 #progressevent

Hi guys,

 

I have a simple nativeprocess code in my app. I unzip password protected zip files using 7zip and want to capture every time a file is unzipped.

 

Here's the code:

 

                    var npInfo:* = new NativeProcessStartupInfo();

 

                    npInfo.executable = app_7za;       

 

                     var args:Vector.<String> = new Vector.<String>;           

                    args.push("e");

                    args.push('');               

                    args.push("-Ptestpass");                   

                    args.push(zipFile.nativePath);

                    args.push('');

                    args.push("-o"+destinationFolder.nativePath);

 

                    npInfo.arguments = args; 

 

                    processBuffer = new ByteArray();

                    nativeProcess = new NativeProcess();

 

                    nativeProcess.addEventListener("standardOutputData",         onStandardOutputData);

                    nativeProcess.addEventListener("standardInputProgress",     onStandardOutputProgress);

                    nativeProcess.addEventListener(NativeProcessExitEvent.EXIT, onStandardOutputClose);

 

                    nativeProcess.addEventListener("standardErrorData",            onIOError);           

                    nativeProcess.addEventListener("standardOutputIoError",      onIOError);

                    nativeProcess.addEventListener("standardErrorIoError",         onIOError);

                    nativeProcess.addEventListener("standardInputIoError",         onIOError);  

 

When I use it, it works, but I can only see the final output and the standardOutputData event doesn't get dispatched during the process.

 

Do you guys have any idea?

 

Thanks in advance.

 

Zsolt

 
Replies
  • Currently Being Moderated
    Jul 25, 2012 1:13 AM   in reply to Vejko

    Thats because output data is used when the executable returns some sort of output stream.

    You can listen on the exit event, which will fire as your process is complete (note: it'll only fire once all the files have extracted, you'd have to do them indvidually to capture each extraction within flash)

     

    private function onExit( event:NativeProcessExitEvent ):void {

                trace("Native Process Exit code: " + event.exitCode);

    }

     

    And you'll get one of these exit codes

     

    Exit Codes from 7-Zip

    7-Zip returns the following exit codes:

    CodeMeaning
    0No error
    1Warning (Non fatal error(s)). For example, one or more files were locked by some other application, so they were not compressed.
    2Fatal error
    7Command line error
    8Not enough memory for operation
    255User stopped the process
     
    |
    Mark as:
  • Currently Being Moderated
    Jul 25, 2012 1:55 AM   in reply to Vejko

    You could use the air File class to periodically read the directory file.getDirectoryListing()

    Why do you need real time? How many files are in there? 7zip is pretty fast. While you're waiting for the exit code, you could set an interval to read the directory every 500ms.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 25, 2012 2:26 AM   in reply to Vejko

    By install do you mean read into flash? Or actually transfer to users machine?

    You could write a shell script that will interact with 7za, extract the files one by one and output the progress.

    I'm reading and wrting files into a zip, and storing a config file in there which keeps info about the zip contents. Then I know I can extract that conf and loop through all the files one by one reading them into flash.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points