0
 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 service pack 2 with Firefox 12

Thanks..

Himanshu
  • 825
  • 2
  • 10
  • 24
  • I meant to point you to [`nsIProcess.kill()`](https://developer.mozilla.org/en/nsIProcess#kill%28%29) but I guess that you want a clean shutdown of the application? – Wladimir Palant May 25 '12 at 11:29
  • @Wladimir Palant - yes, I don't want to use kill(), because it may effect my output, I need something which quit the process or shutdown. – Himanshu May 25 '12 at 11:36

1 Answers1

0

That's not quite trivial - Firefox doesn't have any built-in functionality for that meaning that you would need to use js-ctypes for that and call Win32 API functions directly. Win32 - Get Main Wnd Handle of application describes how you would get hold of the top-level window for an application, after that you can send WM_QUIT message to it. This approach actually works:

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

I tested this and could successfully close a Notepad window with it (the usual warning will appear if the text hasn't been saved so it is a clean shutdown). In your case the problem might be however that you aren't running your ffmpeg directly but rather via the command line shell - so you will close the command line window which might not terminate ffmpeg. I guess you will just have to try, if it doesn't work you will probably have to look at the title of the window instead of its process ID (which is obviously a less reliable approach).

Community
  • 1
  • 1
Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126