Im trying to open a file using the OS's default application, so if i open image.png
on mac it will open with Preview
and on windows Windows Photo Viewer
etc.
Im aware that on OSX you can do open image.png
, but what about windows and linux? Is there a command to open any file with the default application?
Thanks in advance.
CodePudding user response:
for windows you can just type the file name as test.png
to open it, for linux (ubuntu) you can use xdg-open "filename"
CodePudding user response:
I havent done much testing but from googling around it looks like i've found something that should work.
function open(path) {
let command = '';
switch (process.platform) {
case 'darwin':
command = 'open';
break;
case 'win32':
command = 'start';
break;
default:
command = 'xdg-open';
break;
}
return child_process.execSync(`${command} "${path}"`);
}