Skip to content

Instantly share code, notes, and snippets.

@davespanton
Created October 10, 2011 21:31
Show Gist options
  • Save davespanton/1276608 to your computer and use it in GitHub Desktop.
Save davespanton/1276608 to your computer and use it in GitHub Desktop.
Native process example
public var process:NativeProcess;
[Bindable]
public var output:String = "waiting...";
private function onAppComplete():void
{
if( NativeProcess.isSupported )
setupAndLaunch();
else
output = "Not supported";
}
private function setupAndLaunch():void
{
var npsi:NativeProcessStartupInfo = new NativeProcessStartupInfo();
var file:File = File.applicationDirectory.resolvePath("MousePos.exe");
npsi.executable = file; process = new NativeProcess(); process.start( npsi );
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);
}
private function onClosing():void
{
if( process )
process.exit(true);
}
private function onOutputData( event:ProgressEvent ):void
{
output = process.standardOutput.readUTFBytes( process.standardOutput.bytesAvailable );
}
private function onErrorData(event:ProgressEvent):void
{
output = "ERROR -" + process.standardError.readUTFBytes(process.standardError.bytesAvailable);
}
private function onExit(event:NativeProcessExitEvent):void
{
output = "Process exited with " + event.exitCode;
}
private function onIOError(event:IOErrorEvent):void
{
output = event.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment