nsIProcess 编辑
xpcom/threads/nsIProcess.idl
Scriptable This interface represents an executable process. Inherits from: nsISupports
Last changed in Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)Implemented by: @mozilla.org/process/util;1
. To create an instance, use:
var process = Components.classes["@mozilla.org/process/util;1"] .createInstance(Components.interfaces.nsIProcess);
Method overview
void init(in nsIFile executable); |
void initWithPid(in unsigned long pid); Obsolete since Gecko 1.9.2 |
void kill(); |
void run(in boolean blocking, [array, size_is(count)] in string args, in unsigned long count); |
void runAsync([array, size_is(count)] in string args, in unsigned long count, [optional] in nsIObserver observer, [optional] in boolean holdWeak); |
void runw(in boolean blocking, [array, size_is(count)] in wstring args, in unsigned long count); |
void runwAsync([array, size_is(count)] in wstring args, in unsigned long count, [optional] in nsIObserver observer, [optional] in boolean holdWeak); |
Attributes
Attribute | Type | Description |
exitValue | long | The value returned by the process upon exit. This is only valid after the process has exited. Read only. |
isRunning | boolean | true if the process is running, otherwise false . Only accurate if the process was run with blocking disabled. Read only. |
location |
| The location of the executable file on disk. Read only. Gecko 1.9.1 note This attribute is no longer implemented as of Gecko 1.9.1, and is removed entirely in Gecko 1.9.2. |
pid | unsigned long | The process ID of the process. This value is only available after the process has started; in addition, some platforms may not offer this value at all. Read only. |
processName | string | The name of the process. Read only. Gecko 1.9.1 note This attribute is no longer implemented as of Gecko 1.9.1, and is removed entirely in Gecko 1.9.2. |
processSignature | unsigned long | The process signature. Read only. Gecko 1.9.1 note This attribute is no longer implemented as of Gecko 1.9.1, and is removed entirely in Gecko 1.9.2. |
Methods
init()
Initializes the nsIProcess
with the specified executable file. Once initialized, you can start the process executing by calling run()
.
void init( in nsIFile executable );
Parameters
executable
- The
nsIFile
executable file to be represented by thensIProcess
object.
initWithPid()
Obsolete since Gecko 1.9.2 (Firefox 3.6 / Thunderbird 3.1 / Fennec 1.0)Initializes the nsIProcess
to represent an existing process, given that process's ID.
void initWithPid( in unsigned long pid );
Parameters
pid
- The process ID to begin to represent.
kill()
Immediately terminates the process represented by the nsIProcess
object. This only works if the process was run without blocking enabled.
void kill();
Parameters
None.
run()
Starts executing the process.
Gecko 1.9.1 note Prior to Gecko 1.9.1 (Firefox 3.5), this method returned the process ID of the newly executing process. It no longer returns a value.void run( in boolean blocking, [array, size_is(count)] in string args, in unsigned long count );
Parameters
blocking
- If
true
, this method will block until the process terminates; iffalse
, the method returns immediately. args
- An array of
count
arguments, using the native character set, to be passed to the executable on its command line. count
- The number of arguments in the
args
array.
runAsync()
Asynchronously runs the process with which the object was initialized, optionally calling an observer when the process finishes running.
void runAsync( [array, size_is(count)] in string args, in unsigned long count, in nsIObserver observer, Optional in boolean holdWeak Optional );
Parameters
args
- An array of arguments to pass into the process, using the native character set. This array must have
count
entries. count
- The number of arguments passed in the
args
array. observer
Optional- An observer that will be notified when the process exits. The observer will receive this
nsIProcess
instance as the subject and "process-finished" or "process-failed" as the topic. The observer will be notified on the main thread. holdWeak
Optional- If
true
, a weak reference is used to hold the observer.
runw()
Executes the file this object was initialized with.
void runw( in boolean blocking, [array, size_is(count)] in wstring args, in unsigned long count );
Parameters
blocking
- If
true
, this method will block until the process terminates; iffalse
, the method returns immediately. args
- An array of
count
arguments, using UTF-16, to be passed to the executable on its command line. count
- The number of arguments in the
args
array.
runwAsync()
Asynchronously runs the process with which the object was initialized, optionally calling an observer when the process finishes running.
void runwAsync( [array, size_is(count)] in wstring args, in unsigned long count, in nsIObserver observer, Optional in boolean holdWeak Optional );
Parameters
args
- An array of arguments to pass into the process, using UTF-16. This array must have
count
entries. count
- The number of arguments passed in the
args
array. observer
Optional- An observer that will be notified when the process exits. The observer will receive this
nsIProcess
instance as the subject and "process-finished" or "process-failed" as the topic. The observer will be notified on the main thread. holdWeak
Optional- If
true
, a weak reference is used to hold the observer.
Example
// create an nsIFile for the executable
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsIFile);
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);
See also
nsIFile
nsIProcess2
Obsolete since Gecko 1.9.2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论