System/child_process.spawn not working as expected

I am having some issues getting spawn() from the system/child_process SDK module to execute a command successfully on Centos 6.6. I am calling it as

let result = child_process.spawn(command, args, options)

Watching in the debugger, I see that after this step that result contains properties killed: false, exitCode: 0, and a plausible value for the pid. However, I can’t see any evidence that the command was actually executed. I tried running a command that would touch a file and no file was created. I tried running /bin/uname and catching stdout as illustrated in the example here: https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/system_child_process but my callback was not called. I tried making the command /bin/sleep and the argument 60, but when I checked with ps the pid shown in result was not associated with any active process. If I change command to something invalid, result changes to having an exitCode of -1 and the console shows a “File not found” error, so spawn is doing something.

I tried using child_process.spawn on Arch Linux and it worked for me there. What could be different? What could I do to debug this? I’m not seeing any error message.

Have you tried running exec() instead? Also it might be good to run Firefox from the command line to see its output. There might be clues there about this problem.

Tell us what is behind vars command, args and options.

Hi!! , I have tried with the exec command always returns me: Cannot open display. Is possible may have to enable the graphical mode? You know how?

What are you trying to run with exec?

I’m trying to run gnome terminal or any application with GUI (firefox , gedit , etc …). In Windows 7 I have been able to run cmd from the Firefox extension, but in linux not work … I think it’s a problem with the configuration of X11. Any help?

Execute child process with options argument which contains DISPLAY environment variable.
child_process.exec(command, { env: DISPLAY: displayEnv });.

displayEnv is what you get in $DISPLAY in terminal.
But it can not be accessed from add-on, so needs user’s input (e.g. in Add-ons Manager).

system/child_process - Mozilla | MDN

  • in node.js, spawn() and exec() inherit the
    environment variables from the parent process, by default. The SDK
    versions don’t: so when you specify a command you must pass in a
    complete path to the command or use the env option to set up the child process environment.

Also, maybe xhost + need to be set by user.

You can get the $DISPLAY environement variable with the add-on SDK using the env proxy of the sdk/system module. However you have to fetch each value explicitly, the values cannot be enumerated.