Copy link to clipboard
Copied
Here, i am dealing with NativeProcess in AIR (trying to invoke .jar file from AIR app). My Code is next
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="init()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
private var process:NativeProcess;
private function init():void
{
if (NativeProcess.isSupported)
{
Alert.show("suport native process.");
setupAndLaunch();
}
}
private function setupAndLaunch():void
{
var cmdFile:File = new File("c:\\Windows\\System32\\cmd.exe");
var processArgs:Vector.<String> = new Vector.<String>;
processArgs.push("/c"); //Note here
processArgs.push("java -jar xyz.jar");
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.arguments = processArgs;
nativeProcessStartupInfo.executable = cmdFile;
nativeProcessStartupInfo.workingDirectory = File.userDirectory;
process = new NativeProcess();
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
process.addEventListener(NativeProcessExitEvent.EXIT, NativeProcessExitEvent_handler);
process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError);
process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError);
process.start(nativeProcessStartupInfo);
}
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 NativeProcessExitEvent_handler(event:NativeProcessExitEvent😞void
{
trace("Process exited with ", event.exitCode);
}
public function onIOError(event:IOErrorEvent😞void
{
trace(event.toString());
}
]]>
</fx:Script>
</s:WindowedApplication>
it's working great,but problem occurred when i restart my application without closing/killing java process from task manager.it's execution goes in NativeProcessExitEvent_handler box with process exit code 0.
i would like to know why it is happening and How to get rid of it?
please help me in this.