Code snippets:Running applications
MDC
본 페이지에서는 Mozilla XPCOM 인터페이스를 이용해서 chrome JavaScript 코드로 다른 프로그램을 실행하는 방법에 대해 설명하겠습니다. 프로그램을 실행하는데는 두 가지 방법이 있습니다. 첫번째 방법은 nsILocalFile:launch 메소드를 사용하는 것이고, 두번째 방법은 nsIProcess 인터페이스를 사용하는 것입니다.
[편집] nsILocalFile.launch() 이용하기
이 방법은 실행 파일을 더블 클릭하는 것과 동일한 효과가 나타나며 파라미터 없이 실행됩니다. 또 구현되지 않은 플랫폼도 있으므로 여러분이 대상으로 하는 플랫폼에서 이 메소드가 구현되어 있는지 확인해야 합니다.
nsIFile/nsILocalFile에 대한 보다 자세한 정보는 File I/O를 참조하세요.
For more information on nsIFile/nsILocalFile, see File I/O.
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("c:\\myapp.exe");
file.launch();
[편집] nsIProcess 이용하기
nsIProcess 인터페이를 사용하는 것이 권장되는 방법 입니다.
// create an nsILocalFile for the executable
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("c:\\myapp.exe");
// create an nsIProcess
var process = Components.classes["@mozilla.org/process/util;1"]
.createInstance(Components.interfaces.nsIProcess);
process.init(file);
// Run the process.
// If first param is true, calling thread will be blocked until
// called process terminates.
// Second and third params are used to pass command-line arguments
// to the process.
var args = ["argument1", "argument2"];
process.run(false, args, args.length);
[편집] 참고
- nsILocalFile 인터페이스
- nsIProcess 인터페이스
- XPI에 포함된 실행 파일을 실행해야 한다면 Code snippets:File I/O#Getting your extension's folder를 참조하세요.
- 웹 페이지에서 프로세스 실행하기