Adobe AIR 2에서는 제한적으로 프로세스를 실행할 수 있는 기능이 추가되었습니다. NativeProcess클래스인데요. 이 기능을 제공하는 이유는 그런 것 같습니다. AIR에서 안되는 거 C로 짠거랑 데이터 통신할 수 있는 게 주 목적인 듯.
Java처럼 그냥 exe파일 실행하는 것은 안되구요. 샌드박스에 위배되지 않는 파일만 실행할 수 있습니다.
즉, document폴더나 application폴더, 또는 applicationstorage 등과 같은 폴더에 있는 것은 자동으로 실행시킬 수 있지만, 그 외에 파일들은 사용자가 선택한 것만 실행할 수 있습니다. 즉, 열 수 있는 파일과 샌드박스안에 있는 파일만 실행할 수 있다는 얘기죠^^
안그럼 이런 에러가 뜨는 것 같습니다.
NativeProcessStartupInfo.executable does not specify a valid executable file.
뭐 사용자가 exe파일 선택만 해준다면야 모든 실행파일을 실행할 수 있네요.
우선 플래시 빌더를 다운로드를..ㅠㅠ
아래 예제는 그냥 실행파일 선택하면 그 실행파일을 실행해주는 예제입니다.
[code]<?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/halo">
<fx:Script>
<![CDATA[
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.FileFilter;
import mx.controls.Alert;
private var nativeProcess:NativeProcess;
protected function btnRun_clickHandler(event:MouseEvent):void
{
if (NativeProcess.isSupported)
{
var file:File = new File();
file.addEventListener(Event.SELECT, selectHandler);
file.browseForOpen("실행파일을 선택하세요", [new FileFilter("exe파일", "*.exe")]);
}
else
{
Alert.show("NativeProcess를 지원하지 않음.");
}
}
private function selectHandler(event:Event):void
{
var file:File = event.currentTarget as File;
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
//var args:Vector.<String> = new Vector.<String>;
//args.push("/root,c:\\");
//nativeProcessStartupInfo.arguments = args;
nativeProcessStartupInfo.executable = file;
nativeProcess = new NativeProcess();
nativeProcess.start(nativeProcessStartupInfo);
}
]]>
</fx:Script>
<s:Button id="btnRun" label="실행파일 선택" click="btnRun_clickHandler(event)"/>
</s:WindowedApplication>[/code]
예제의 핵심은 NativeProcess클래스랑 NativeProcessStartupInfo클래스입니다.
NativeProcessStartupInfo클래스에 해당 file이랑 arguments를 넣어주고, NativeProcess로 실행하면 됩니다^^
그리고 Descriptor파일에 한줄 추가해줘야 하는 것 같은데요.
[code]<supportedProfiles>extendedDesktop</supportedProfiles>[/code]
왜 추가 안해도 잘 되지-_- 깜빡하고 추가안했는데, 잘 돼요. 이거 추가안하면 통신이 안되나...암튼 잘 모르겠네요.
근데, 저거 추가하고, Flash Builder에서 제공하는 빌더로 export하면 에러납니다-_-
[code]Error creating AIR file: NativeProcessTest-app.xml: error 306: Descriptor must support the profile desktop, mobileDevice, or extendedMobileDevice.[/code]
이거 웬지 Builder에서 제공하는 것은 1.5로 패키징하는 것 같음-_-
암튼, 저거 빼고 해서 air파일을 만들어도 실행하면 설치가 안됩니다. 이런 에러메세지가 나는군요.
[code]This application has been designed for a different device profile and will not run on your system. Contact the application author to see if a compatible version is available.[/code]
그래서 adt를 이용해서 command line으로 직접 패키징을 해야합니다. 아.....난 콘솔이 싫은데.....
우선 amxmlc로 컴파일합니다.
[code]amxmlc NativeProcess.mxml[/code]
그러면 NativeProcess.swf파일이 생김.
이제 패키징을 하면 됩니다.
[code]adt -package -storetype pkcs12 -keystore c:\Users\mudchobo\Documents\mudchobo.p12 -target native NativeProcessTest.exe NativeProcessTest-app.xml NativeProcessTest.swf[/code]
-keystore값에는 자기인증서 경로를 적구요. -target은 native로 하면 exe파일로 생성됩니다.
그리고 포함할 파일을 적으면 되구요.
그리고 빌더로 만든 *-app.xml파일을 보시면 <content>태그가
[code]<content>[This value will be overwritten by Flash Builder in the output app.xml]</content>[/code]로 되어있는데, 이거 swf파일 경로 적어 줘야합니다.
[code]<content>NativeProcess.swf</content>[/code]
비밀번호 입력하면 NativeProcessTest.exe파일이 생성되는데, 그거 실행하면 설치화면이 뜹니다.
이 설치파일은 기존 air파일로 패키징한거랑 틀리게 배경이 흰색이네요-_-
암튼, 설치하고 나면 실행 잘 됩니다.
※참고로 제가 탐섹히를 실행하려고 해봤는데, 이런 기능이 필요한 이유가 어떤 다운로드프로그램에서 사용자가 받은 파일이 있는 폴더를 손쉽게 열 수 있게 하는 것이 목표인데, 그럴려면 탐색기 실행이 필요합니다.
그래서 그냥 패키징할 때 탐색기 프로그램을 같이 패키징해버리면 보안샌드박스에 있기 때문에 실행할 수 있습니다-_-
c:\Windows\explorer.exe파일을 복사해서 패키징해버리고, 실행하면 탐색히가 뜹니다.
해당 폴더를 여는건 explorer.exe /root,c:\\로 하면 된다는.......-_-
마지막으로 다시한번 플래시빌더를 다운로드를-_-
참고자료
http://www.adobe.com/devnet/air/flex/quickstart/interacting_with_native_process.html
Java처럼 그냥 exe파일 실행하는 것은 안되구요. 샌드박스에 위배되지 않는 파일만 실행할 수 있습니다.
즉, document폴더나 application폴더, 또는 applicationstorage 등과 같은 폴더에 있는 것은 자동으로 실행시킬 수 있지만, 그 외에 파일들은 사용자가 선택한 것만 실행할 수 있습니다. 즉, 열 수 있는 파일과 샌드박스안에 있는 파일만 실행할 수 있다는 얘기죠^^
안그럼 이런 에러가 뜨는 것 같습니다.
NativeProcessStartupInfo.executable does not specify a valid executable file.
뭐 사용자가 exe파일 선택만 해준다면야 모든 실행파일을 실행할 수 있네요.
우선 플래시 빌더를 다운로드를..ㅠㅠ
아래 예제는 그냥 실행파일 선택하면 그 실행파일을 실행해주는 예제입니다.
[code]<?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/halo">
<fx:Script>
<![CDATA[
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.FileFilter;
import mx.controls.Alert;
private var nativeProcess:NativeProcess;
protected function btnRun_clickHandler(event:MouseEvent):void
{
if (NativeProcess.isSupported)
{
var file:File = new File();
file.addEventListener(Event.SELECT, selectHandler);
file.browseForOpen("실행파일을 선택하세요", [new FileFilter("exe파일", "*.exe")]);
}
else
{
Alert.show("NativeProcess를 지원하지 않음.");
}
}
private function selectHandler(event:Event):void
{
var file:File = event.currentTarget as File;
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
//var args:Vector.<String> = new Vector.<String>;
//args.push("/root,c:\\");
//nativeProcessStartupInfo.arguments = args;
nativeProcessStartupInfo.executable = file;
nativeProcess = new NativeProcess();
nativeProcess.start(nativeProcessStartupInfo);
}
]]>
</fx:Script>
<s:Button id="btnRun" label="실행파일 선택" click="btnRun_clickHandler(event)"/>
</s:WindowedApplication>[/code]
예제의 핵심은 NativeProcess클래스랑 NativeProcessStartupInfo클래스입니다.
NativeProcessStartupInfo클래스에 해당 file이랑 arguments를 넣어주고, NativeProcess로 실행하면 됩니다^^
그리고 Descriptor파일에 한줄 추가해줘야 하는 것 같은데요.
[code]<supportedProfiles>extendedDesktop</supportedProfiles>[/code]
왜 추가 안해도 잘 되지-_- 깜빡하고 추가안했는데, 잘 돼요. 이거 추가안하면 통신이 안되나...암튼 잘 모르겠네요.
근데, 저거 추가하고, Flash Builder에서 제공하는 빌더로 export하면 에러납니다-_-
[code]Error creating AIR file: NativeProcessTest-app.xml: error 306: Descriptor must support the profile desktop, mobileDevice, or extendedMobileDevice.[/code]
이거 웬지 Builder에서 제공하는 것은 1.5로 패키징하는 것 같음-_-
암튼, 저거 빼고 해서 air파일을 만들어도 실행하면 설치가 안됩니다. 이런 에러메세지가 나는군요.
[code]This application has been designed for a different device profile and will not run on your system. Contact the application author to see if a compatible version is available.[/code]
그래서 adt를 이용해서 command line으로 직접 패키징을 해야합니다. 아.....난 콘솔이 싫은데.....
우선 amxmlc로 컴파일합니다.
[code]amxmlc NativeProcess.mxml[/code]
그러면 NativeProcess.swf파일이 생김.
이제 패키징을 하면 됩니다.
[code]adt -package -storetype pkcs12 -keystore c:\Users\mudchobo\Documents\mudchobo.p12 -target native NativeProcessTest.exe NativeProcessTest-app.xml NativeProcessTest.swf[/code]
-keystore값에는 자기인증서 경로를 적구요. -target은 native로 하면 exe파일로 생성됩니다.
그리고 포함할 파일을 적으면 되구요.
그리고 빌더로 만든 *-app.xml파일을 보시면 <content>태그가
[code]<content>[This value will be overwritten by Flash Builder in the output app.xml]</content>[/code]로 되어있는데, 이거 swf파일 경로 적어 줘야합니다.
[code]<content>NativeProcess.swf</content>[/code]
비밀번호 입력하면 NativeProcessTest.exe파일이 생성되는데, 그거 실행하면 설치화면이 뜹니다.
이 설치파일은 기존 air파일로 패키징한거랑 틀리게 배경이 흰색이네요-_-
※참고로 제가 탐섹히를 실행하려고 해봤는데, 이런 기능이 필요한 이유가 어떤 다운로드프로그램에서 사용자가 받은 파일이 있는 폴더를 손쉽게 열 수 있게 하는 것이 목표인데, 그럴려면 탐색기 실행이 필요합니다.
그래서 그냥 패키징할 때 탐색기 프로그램을 같이 패키징해버리면 보안샌드박스에 있기 때문에 실행할 수 있습니다-_-
c:\Windows\explorer.exe파일을 복사해서 패키징해버리고, 실행하면 탐색히가 뜹니다.
해당 폴더를 여는건 explorer.exe /root,c:\\로 하면 된다는.......-_-
마지막으로 다시한번 플래시빌더를 다운로드를-_-
참고자료
http://www.adobe.com/devnet/air/flex/quickstart/interacting_with_native_process.html
TAG Adobe,
adobe air,
adobe air 2,
AIR,
Flash builder,
flex,
Flex4,
Native,
nativeprocess,
어도비,
에어,
플래시 빌더,
플렉스
댓글을 달아 주세요
와우~ AIR2 에서 달라진게 뭐가 있는 두리번 거리고 있었는데 이건 조금 대박이네요. 결국 샌드박스 안에만 있으면 .exe 파일을 실행 시킬 수 있다는 의미인거죠? 당장 내일 테스트 해봐야겠습니다.
네 자기가 c나 다른 언어로 짠 것을 air에 포함시켜서 그 프로그램과 통신도 할 수 있죠.
방문해주셔서 감사해요~ ^^
근데요 꼭 c로 짠 exe만 실행할 수 있나요???
C# 으로 짠 exe는 상호 통신할 수 없나요???
혹 있으시면 알려주세요 ㅠ
안녕하세요 우선 정보 감사합니다.
Flex3에서 NativeProcess관련해서 설명해주신대로 수동 컴파일까지는 성공했습니다.
컴파일된 exe파이를 설치를 하고 실행까지는 잘 동작합니다.
그런데 nativeProcess관련하여 commandLine 명령어를 지원하는 exe 프로그램이 AIR에서 start를 하면
커맨트창이 잠깐 보였다가 실행되고 꺼집니다...
이창을 숨기거나 안나오게 하는 방법이 있는지요?
^____________^
안녕하세요~
저도....NativeProcess그냥 나왔을 때 잠깐 해본거라ㅠㅠ
잘 모르겠습니다 ㅠㅠ
비밀댓글입니다
음...혹시...프로젝트이름을 NativeProcess로 하셨나요?
몬가 충돌이 일어나는 것 같아보이는데....
머드초보님..
저는 플렉스는 모르지만 플래시는 아는데요.
Flash CS5로 그냥 텍스트툴을 사용해서 t라는 텍스트필드를 만들고
t.text = NativeProcess.isSupported.toString();
이렇게 액션을 준 후 app xml에는 다음과 같이 주었습니다.
<supportedprofiles>extendedDesktop desktop</supportedprofiles>
그리고 플래시 속성창의 Air2 설정의 [편집]버튼을 눌러서 제작 버튼을 누르면 air파일은 만들어지는데
<supportedprofiles>노드가 없어져 버립니다.
그래서 air파일을 실행해서 보면 텍스트필드에도 NativeProcess.isSupported가 false로 나옵니다.
<supportedprofiles>extendedDesktop</supportedprofiles> 이렇게만 줘도 없어져 버리거든요.
어떻게 하면 <supportedprofiles>노드를 없애지 않을 수 있을까요?
음...이거 베타 때 한것이고, Flash에서 해보질 않아서 잘 모르겠네요ㅠㅠ
뭔가 정책이 바뀐 것 같은데, adobe 문서를 확인해보시면ㅠㅠ