Skip to content

Instantly share code, notes, and snippets.

@pwlin
Last active June 26, 2019 21:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pwlin/9068069 to your computer and use it in GitHub Desktop.
Save pwlin/9068069 to your computer and use it in GitHub Desktop.
nodejs open external program
function testExternalApp(){
//////////////////////////////////
// http://stackoverflow.com/questions/18183882/node-webkit-how-to-execute-an-exe-file
// https://github.com/rogerwang/node-webkit/wiki/Clipboard
var execFile = require('child_process').execFile, child;
child = execFile('C:\\Program Files\\Microsoft Office\\Office12\\winword.exe', function(error,stdout,stderr) {
if (error) {
//console.log(error.stack);
//console.log('Error code: '+ error.code);
//console.log('Signal received: '+
// error.signal);
}
//console.log('Child Process stdout: '+ stdout);
//console.log('Child Process stderr: '+ stderr);
});
child.on('exit', function (code) {
//console.log('Child process exited '+
// 'with exit code '+ code);
//alert('exit');
// Load native UI library
var gui = require('nw.gui');
var clipboard = gui.Clipboard.get();
var text = clipboard.get('text');
alert(text);
});
///////////////////////////////////
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment