InvisibleUn1corn InvisibleUn1corn - 1 year ago 120
Node.js Question

open a file with default program in node-webkit

I want to give the user any option he want to edit a file, how can I open a file with the default program of the specific file type? I need it to work with Windows and Linux but Mac option would be great too.

Answer Source

as PSkocik said, first detect the platform and get the command line :

function getCommandLine() {
   switch (process.platform) { 
      case 'darwin' : return 'open';
      case 'win32' : return 'start';
      case 'win64' : return 'start';
      default : return 'xdg-open';

second , execute the command line followed by the path

var sys = require('sys');
var exec = require('child_process').exec;

exec(getCommandLine() + ' ' + filePath);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download