var fpath="C:\\TVT_"+cur_date+"_"+cur_time+".avi";
Components.utils.import("resource://gre/modules/FileUtils.jsm");
var env = Components.classes["@mozilla.org/process/environment;1"]
.getService(Components.interfaces.nsIEnvironment);
var shell = new FileUtils.File(env.get("COMSPEC"));
var args = ["/c", "cd.. & cd.. & C: & cd C:/ffmpeg/bin & record.bat "+fpath];
var process = Components.classes["@mozilla.org/process/util;1"]
.createInstance(Components.interfaces.nsIProcess);
process.init(shell);
process.runAsync(args, args.length);
在Firefox 12中使用Windows XP Service Pack 2
谢谢..
答案 0 :(得分:0)
这并不是一件容易的事 - Firefox没有任何内置功能,你需要使用js-ctypes来直接调用Win32 API函数。 Win32 - Get Main Wnd Handle of application描述了如何获取应用程序的顶级窗口,之后您可以向其发送WM_QUIT
消息。这种方法确实有效:
Components.utils.import("resource://gre/modules/ctypes.jsm");
var userlib = ctypes.open("user32");
var HWND = ctypes.voidptr_t;
var UINT = ctypes.uint32_t;
var WPARAM = ctypes.uint16_t;
var LPARAM = ctypes.uint32_t;
var LRESULT = ctypes.uint32_t;
var DWORD = ctypes.uint32_t;
var WNDENUMPROC = ctypes.FunctionType(ctypes.stdcall_abi,
ctypes.bool,
[HWND, LPARAM]).ptr;
var WM_CLOSE = 0x0010;
var EnumWindows = userlib.declare(
"EnumWindows", ctypes.winapi_abi,
ctypes.bool,
WNDENUMPROC, LPARAM
);
var GetWindowThreadProcessId = userlib.declare(
"GetWindowThreadProcessId", ctypes.winapi_abi,
DWORD,
HWND, DWORD.ptr
);
var IsWindowVisible = userlib.declare(
"IsWindowVisible", ctypes.winapi_abi,
ctypes.bool,
HWND
);
var SendMessage = userlib.declare(
"SendMessageW", ctypes.winapi_abi,
LRESULT,
HWND, UINT, WPARAM, LPARAM
);
var callback = WNDENUMPROC(function(hWnd, lParam)
{
var procId = DWORD();
GetWindowThreadProcessId(hWnd, procId.address());
if (procId.value == pid && IsWindowVisible(hWnd))
SendMessage(hWnd, WM_CLOSE, 0, 0);
return true;
});
EnumWindows(callback, 0);
userlib.close();
我测试了这个并且可以用它成功关闭一个记事本窗口(如果文本尚未保存,则会显示通常的警告,因此它是一个干净的关闭)。在您的情况下,问题可能是您没有直接运行ffmpeg而是通过命令行shell - 因此您将关闭可能不会终止ffmpeg的命令行窗口。我想你只需要尝试,如果它不起作用,你可能不得不查看窗口的标题而不是它的进程ID(这显然是一种不太可靠的方法)。