English 中文(简体)
如何将退出命令发送到当前 ffmpeg.exe?
原标题:How can I send quit command to current ffmpeg.exe
 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);
  1. I don t want to use taskkill.exe, /MIN, /C, /B, rather I want to quit this ffmpeg process
  2. I read about CMDOW but did not find cmdow.exe inside system32 directory.
  3. So how can I send quit command within the same window which is running ffmpeg process?

Using Windows XP 服务包 2, 配有 Firefox 12

谢谢

最佳回答

并非微不足道的 ─ Firefox 没有任何内在功能, 这意味着您需要使用 < a href=" https:// developmenter.mozilla.org/ en/js- ctyms/" rel=" nofollow noreferr" >js- ctypes , 并直接拨打 Win32 API 函数 。 < a href=" https://stackoverflow.com/ questions/6202547/win32- get-main- wnd- handle-of-aplict > > > win32 - 获取应用程序的主 Wind Handle 描述您在发送 < codead> WMUIT < /codead mess > 之后如何获得顶级窗口的应用程序 。

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();

我测试了这一点, 并能够成功关闭一个 Notespad 窗口( 如果文本没有保存, 通常的警告将会出现, 这样它就是一个干净的关机 ) 。 在您的情况中, 问题可能在于您没有直接运行 ffmpeg, 而是通过命令行 shell 来运行 。 这样您就可以关闭命令行窗口, 它可能不会终止 ffmpeg 。 我猜您必须尝试一下, 如果它不起作用, 您可能不得不查看窗口的标题而不是其进程 ID ( 这显然不太可靠 ) 。

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签