7 Replies Latest reply on Jun 16, 2010 9:40 AM by thilgen

    Air 2.0 NativeProcess Communication Problem

    pseudohybriddesign

      Hello,

       

      I'm working on an AIR 2 application (a packager for air applications into *.exe). One of the options in the application is to check the validity of certificate's password. I'm using standardOutput method:

       

      private function checkCertPass():void{
      
                  file = new File();
      
                  file.nativePath = "C:/WINDOWS/system32/"
      
                  file = file.resolvePath("cmd.exe");
      
                  nativeProcessStartupInfo = new NativeProcessStartupInfo();
      
                  var processArgs:Vector.<String> = new 
      Vector.<String>;
      
                  processArgs.push(javaPath.text);
      
                  processArgs.push("-jar");
      
                  processArgs.push(adtPath.text);
      
                  processArgs.push("-checkstore");
      
                  processArgs.push("-storetype");
      
                  processArgs.push("pkcs12");
      
                  processArgs.push("-keystore");
      
                  processArgs.push(certPath.text);
      
                  processArgs.push("-storepass");
      
                  processArgs.push(passField.text);           
      
                  nativeProcessStartupInfo.arguments = processArgs;
      
                  nativeProcessStartupInfo.executable = file;
      
                  nativeProcess = new NativeProcess();
      
                  
      nativeProcess.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, 
      onCertOutputData);
      
                  nativeProcess.start(nativeProcessStartupInfo);
      
              }
      
              private function onCertOutputData(event:ProgressEvent):void{
      
                  var certResponse:String = new String();
      
                  certResponse = 
      nativeProcess.standardOutput.readUTFBytes(nativeProcess.standardOutput.bytesAvailable);
      
                  trace(certResponse);
      
                  outputField.enabled = true;
      
                  outputField.text += certResponse;
      
                  if(certResponse.substr(0,5) == "valid"){
      
                      trace("Correct password!");
      
                      exeField.enabled = true;
      
                      
      nativeProcess.removeEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, 
      onCertOutputData);
      
                      nativeProcess.exit();
      
                  }else{
      
                      trace("Incorrect password! Error...");
      
                      exeField.enabled = false;
      
                      
      nativeProcess.removeEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, 
      onCertOutputData);
      
                      nativeProcess.exit();
      
                  }
      
              }
      

       

      but I cannot establish communication i.e. all I receive after performing the code above is:

       

      Microsoft Windows XP [Version 5.1.2600]
      
      (C) Copyright 1985-2001 Microsoft Corp.
      
      
      C:\Program Files\Adobe\Flex Builder 3>
      

       

      What is wrong with this code? Why I can't receive the response?

       

      Thanks in advance,
      Nikola

        • 1. Re: Air 2.0 NativeProcess Communication Problem
          thilgen Level 4

          What happens if you add

           

            processArgs.push("/c");

           

          before

           

            processArgs.push(javaPath.text);

            processArgs.push("-jar");

           

          Chris Thilgen
          AIR Engineering

          • 2. Re: Air 2.0 NativeProcess Communication Problem
            pseudohybriddesign Level 1

            Hi thilgen! First of all, thank you for your reply.

             

            I've tried your suggestion but in comparison to the preious output, now the output is totally blank (nothing is traced)...

             

            I really don't know where is the problem. Why I can't receive the answer "valid password" and subsequently to check it? If I write the code directly in the cmd console, everything is ok...

            • 3. Re: Air 2.0 NativeProcess Communication Problem
              thilgen Level 4

              Oops - I did not look at your original example close enough - please try this:

              file = new File(javaPath.text); // assume this is the path to java.exe...

               

              var processArgs:Vector.<String> = new Vector.<String>;
              processArgs.push("-jar");
              processArgs.push(adtPath.text);
              processArgs.push("-checkstore");
              processArgs.push("-storetype");
              processArgs.push("pkcs12");
              processArgs.push("-keystore");
              processArgs.push(certPath.text);
              processArgs.push("-storepass");
              processArgs.push(passField.text);         

              nativeProcessStartupInfo = new NativeProcessStartupInfo();
              nativeProcessStartupInfo.executable = file;

              nativeProcessStartupInfo.arguments = processArgs;

               

              nativeProcess = new NativeProcess();
              nativeProcess.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onCertOutputData);
              nativeProcess.start(nativeProcessStartupInfo);

               

              Thanks,

               

              Chris Thilgen

              AIR Engineering

              • 5. Re: Air 2.0 NativeProcess Communication Problem
                thilgen Level 4

                Okay Take 2:

                 

                <?xml version="1.0" encoding="utf-8"?>
                <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
                <mx:Script>
                  <![CDATA[
                  private var nativeProcess:NativeProcess;
                  
                  private function onGo() : void {
                   outputField.text = "";
                  
                   var file:File = new File("C:\\Program Files\\Java\\jdk1.6.0_20\\bin\\java.exe");
                  
                   var processArgs:Vector.<String> = new Vector.<String>;
                   processArgs.push("-jar");
                   processArgs.push("C:\\Documents and Settings\\cthilgen\\Desktop\\sdk_0512\\lib\\adt.jar");
                   processArgs.push("-checkstore");
                   processArgs.push("-storetype");
                   processArgs.push("pkcs12");
                   processArgs.push("-keystore");
                   processArgs.push("C:\\Documents and Settings\\cthilgen\\Desktop\\cert-test\\test.p12"); // password is 'testpass'
                   processArgs.push("-storepass");
                   processArgs.push(passField.text);          
                  
                   var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
                   nativeProcessStartupInfo.arguments = processArgs;
                   nativeProcessStartupInfo.executable = file;
                   nativeProcess = new NativeProcess();
                   nativeProcess.addEventListener(ProgressEvent.STANDARD_ERROR_DATA,onCertOutputData);
                   nativeProcess.start(nativeProcessStartupInfo);
                  }
                  
                  private function onCertOutputData(event:ProgressEvent) : void {
                   var certResponse:String = new String();
                   certResponse = nativeProcess.standardError.readUTFBytes(nativeProcess.standardError.bytesAvailable);
                   trace(certResponse);
                   outputField.text += certResponse;  
                   if ( certResponse.substr(0,5) == "valid") {
                    trace("Correct password!");
                    nativeProcess.removeEventListener(ProgressEvent.STANDARD_ERROR_DATA,onCertOutputData);
                    nativeProcess.exit();
                   } else {
                    trace("Incorrect password! Error...");
                    nativeProcess.removeEventListener(ProgressEvent.STANDARD_ERROR_DATA,onCertOutputData);
                    nativeProcess.exit();
                   }
                  }
                  
                  ]]>
                </mx:Script>

                <mx:Button label="go" click="onGo()" />
                <mx:TextInput id="passField"/>
                <mx:TextArea id="outputField" width="100%" height="100%"/>

                </mx:WindowedApplication>

                Please let me know if this gets you sorted.

                 

                Thanks,

                 

                Chris Thilgen

                AIR Engineering

                • 6. Re: Air 2.0 NativeProcess Communication Problem
                  pseudohybriddesign Level 1

                  Hello thilgen. Problem is solved. Thank you once again for all your help.

                   

                  Best regards,

                  Nikola

                  • 7. Re: Air 2.0 NativeProcess Communication Problem
                    thilgen Level 4

                    Excellent! Please let us know if you encounter any further issues.

                     

                    Chris Thilgen

                    AIR Engineering