1

I am creating a Firefox extension that calls a Linux shared library via the js-ctypes mechanism. I want my extension to display debug information on a standard terminal by calling a function in my shared library which then simply calls printf() to display the debug string on a terminal.

However, my application has no terminal. So, is there a way my shared library can open, display and printf() to display such messages?

Yes, I know about the built-in error and browser windows. But for obscure reasons I want to send my debug messages in a terminal window.

So, how can my shared library open and display a terminal to printf() into?

honestann
  • 1,374
  • 12
  • 19

2 Answers2

1
  • Since you're on Linux anyway, when running Firefox from the command line, it will print some stuff to stdout (or was it stderr) already. Same on MAC. Windows may need the -console switch. Your library that was loaded via js-ctypes could just use printf() and/or fprintf(stderr,...). I seem remember using printf myself when developing js-ctypes stuff in the past.
  • You can also use dump in JS code. This will only ever dump to the terminal, but not the Browser Console.
  • Lastly the Components.utils.reportError enables you to print arbitrary messages to th global Browser Console (formerly Error Console). Cu.reportError is basically a shortcut to nsIConsoleService, which will also generate appropriate location information.
nmaier
  • 32,336
  • 5
  • 63
  • 78
  • At the top of my extension javascript program is this line: `var econsole = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);` ::: Then all over my extension program are print statements that look like this: `econsole.logStringMessage("funcname() : variable = " + variable);` ::: This prints to both the error console and browser console. Is this inferior to what you mention, or the same? – honestann Dec 11 '13 at 12:47
  • Also, strange that `dump(string);` and `window.dump(string);` do not output anything into the error console or browser console even though `about:config` shows `browser.dom.window.dump.enabled` is `true`. But all my `econsole.logStringMessage()` do output to both the error console and browser console. Hmmm. – honestann Dec 11 '13 at 13:00
  • `Cu.reportError` uses `nsIConsoleService`, but does generate proper error messages linking the source when passed errors and exceptions. `dump` will only ever print to the terminal console (if a stdout/sterr is attached to the program, e.g. when run from command line). – nmaier Dec 11 '13 at 13:05
0

You should probably create a simple server that connects to a named pipe and reads data, then prints it to its stdout. It would just be a simple program that connects to a pipe (like a file), and reads from it.

You can use mkfifo to create the named pipe, and your javascript app can write to it, just like you would a file.

A related question is here: How to send a simple string between two programs using pipes?

You can use the command line mkfifo tool, or use the standard C function.

Community
  • 1
  • 1
johannestaas
  • 1,175
  • 1
  • 9
  • 15