如何解决使用firefox启动在系统PATH中找到的外部程序
||
我有一个插件,我想用来启动计算机上已经安装的程序,例如notepad.exe
问题是,Firefox似乎没有在系统PATH中搜索该程序,即
file.initWithPath(\"c:\\\\windows\\\\system32\\\\notepad.exe\");//works
//file.initWithPath(\"notepad.exe\");//does not work
//file.initWithPath(\"%systemroot%\\\\notepad.exe\");//does not work
题:
有没有办法让Firefox在系统PATH中查找程序?
这是我的完整功能
autoStartNotepad:function()
{
// create an nsILocalFile for the executable
var file = Components.classes[\"@mozilla.org/file/local;1\"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(\"notepad.exe\");//does not work
//but file.initWithPath(\"c:\\\\windows\\\\system32\\\\notepad.exe\");//works
// 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 = [];
process.run(false,args,args.length);
}
解决方法
nsIProcess
不会这样做,它只接受完整路径。您需要亲自查看环境变量:
var environment = Components.classes[\"@mozilla.org/process/environment;1\"]
.getService(Components.interfaces.nsIEnvironment);
var path = environment.get(\"PATH\");
var root = environment.get(\"SYSTEMROOT\");
您可以拆分
PATH
变量并检查各个目录,也可以使用
SYSTEMROOT
变量的值。
您可以运行
cmd.exe /c notepad.exe
,但也需要首先定位
cmd.exe
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。