- private function runProcess():void
- {
- if (!NativeProcess.isSupported)
- {
- Alert.show("当前系统不支持");
- return;
- }
- try
- {
- var file:File;
- // Use default paths for ping... modify if your system does not use the default path
- if (Capabilities.os.toLowerCase().indexOf("win") > -1)
- {
- file = new File("<a href="c://windows//system32//cmd.exe">c://windows//system32//cmd.exe");
- }
- else if (Capabilities.os.toLowerCase().indexOf("mac") > -1)
- {
- //
- }
- else if (Capabilities.os.toLowerCase().indexOf("linux") > -1)
- {
- //
- }
- var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
- nativeProcessStartupInfo.executable = file;
- process = new NativeProcess();
- process.start(nativeProcessStartupInfo);
- process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, stdoutHandler);
- process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA,errorHandler);
- }
- catch (e:Error)
- {
- Alert.show(e.message, "Error");
- }
- }
- private function stdoutHandler(event:ProgressEvent):void
- {
- var process:NativeProcess = event.target as NativeProcess;
- var data:String = process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable);
- }
- private function errorHandler(event:ProgressEvent):void
- {
- var process:NativeProcess = event.target as NativeProcess;
- var data:String = process.standardError.readUTFBytes(process.standardError.bytesAvailable);
- }
- //该片段来自于http://www.codesnippet.cn/detail/250420133040.html
来源: http://www.codesnippet.cn/detail/250420133040.html