1 Reply Latest reply on Sep 15, 2010 8:57 AM by etoele

    How to run commands like “ipconfig” and get the output in adobe AIR in windows?

    DynamicLiveVideoDeliver

      import flash.desktop.NativeProcess; 

      import flash.desktop.NativeProcessStartupInfo;   

      if (NativeProcess.isSupported) {     

           var npsi:NativeProcessStartupInfo = new NativeProcessStartupInfo();     

           var processpath:File = File.applicationDirectory.resolvePath("MyApplication.whatever");     

           var process:NativeProcess = new NativeProcess();       

           npsi.executable = processpath;     

           process.start(npsi); 

      } 

       

       

      The above can only run a sub-application, but how to run an independent  application(command) like ipconfig and get the result?

        • 1. Re: How to run commands like “ipconfig” and get the output in adobe AIR in windows?
          etoele

          Hi,

           

          here is an example of running a net Use command line from AIR, unig the new NativeProcess. Hope it will help !

           

          function launchProcess()
          {
            var file = air.File.applicationDirectory;
           
            // set command path
            file = file.resolvePath("C:/Windows/system32/net.exe");
           
            var nativeProcessStartupInfo = new air.NativeProcessStartupInfo();
            nativeProcessStartupInfo.executable = file;
           
            // prepare command parameters
            var args = new runtime.Vector["<String>"]();
            args.push('USE');
            args.push('W:');
            args.push('/delete');
            args.push('/y');
           
            // set arguments
            nativeProcessStartupInfo.arguments = args;
           
            // add listeners to catch command outputs
            process.addEventListener(air.ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
            process.addEventListener(air.ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
            process.addEventListener(air.NativeProcessExitEvent.EXIT, onExit);
           
            // create and run Native process
            process = new air.NativeProcess();
            process.start(nativeProcessStartupInfo);
          }
          function onOutputData(ProgressEvent)
          {
            var processResults = process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable);
            air.trace("Results: \n" + processResults);
                 
          }
          function onErrorData(ProgressEvent)
          {
            var processResults = process.standardError.readUTFBytes(process.standardError.bytesAvailable);
            if(processResults.search('password') > -1){
              window.alert('Bad password');
            }
            air.trace("Errors: \n" + processResults);

           

          }              
          function onExit(NativeProcessExitEvent)
          {
            air.trace("Process ended with code: " + NativeProcessExitEvent.exitCode);
          }