Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

AS3 NativeProcess launch application

Participant ,
Jan 26, 2015 Jan 26, 2015

Hello All. I am trying to launch a program from an AIR file. I have been pointed to NativeProcess as the scripting to use for launching a program. For testing purposes I am trying to launch Photoshop CC on my MAC.  Below is the code I have tested but I keep getting an error.

Does anyone have any input on where I might have gone wrong?

- - - - - - - - -

package

{

    import flash.display.Sprite;

    import flash.desktop.NativeProcess;

    import flash.desktop.NativeProcessStartupInfo;

    import flash.events.Event;

    import flash.events.ProgressEvent;

    import flash.events.IOErrorEvent;

    import flash.events.NativeProcessExitEvent;

    import flash.filesystem.File;

  

    public class NativeProcessExample extends Sprite

    {

        public var process:NativeProcess;

        public function NativeProcessExample()

        {

            if(NativeProcess.isSupported)

            {

                setupAndLaunch();

            }

            else

            {

                trace("NativeProcess not supported.");

            }

        }

      

        public function setupAndLaunch():void

        {   

            var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();

            var file:File = File.applicationDirectory.resolvePath("/Applications/Adobe Photoshop CC/Adobe Photoshop CC.app/Contents/MacOS/Adobe Photoshop CC");

            nativeProcessStartupInfo.executable = file;

            var processArgs:Vector.<String> = new Vector.<String>();

            processArgs[0] = "foo";

            nativeProcessStartupInfo.arguments = processArgs;

            process = new NativeProcess();

            process.start(nativeProcessStartupInfo);

            process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);

            process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);

            process.addEventListener(NativeProcessExitEvent.EXIT, onExit);

            process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError);

            process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError);

        }

        public function onOutputData(event:ProgressEvent):void

        {

            trace("Got: ", process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable));

        }

      

        public function onErrorData(event:ProgressEvent):void

        {

            trace("ERROR -", process.standardError.readUTFBytes(process.standardError.bytesAvailable));

        }

      

        public function onExit(event:NativeProcessExitEvent):void

        {

            trace("Process exited with ", event.exitCode);

        }

      

        public function onIOError(event:IOErrorEvent):void

        {

             trace(event.toString());

        }

    }

}

- - - - - - - - - -

When I run this an error 1046: Type was not found or was not a compile-time constant: NativeProcessExitEvent.

The error is referencing the code, 4 lines up from the bottom in the sample above..

Does anyone have any input on where I may have made my mistake?

Thank you.

TOPICS
ActionScript
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 28, 2015 Jan 28, 2015

Do you need to know when it exits? I mean you could just remove the listener for the exit event and see if it works. I start powershell sometimes and have no listeners on the process and it works fine. Also, have you tried without the "foo" argument?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 28, 2015 Jan 28, 2015

Hello dmennenoh,

Thank you for your reply.

The code I used is what Adobe documentation provided as an example. I do not understand every element of the code.

With your suggestion I should delete the following bits of code?

- - - - - - -

processArgs[0] = "foo";


process.addEventListener(NativeProcessExitEvent.EXIT, onExit);


  public function onExit(event:NativeProcessExitEvent):void

        {

            trace("Process exited with ", event.exitCode);

        }

- - - - - - - - - -

Thank you for your help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 28, 2015 Jan 28, 2015
LATEST

That'd be a start anyway...Did you try it?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines