node-unoconv
node-unoconv copied to clipboard
Error: spawn ENOENT on Windows 8
When I do this (I'm using coffeescript):
unoconv.convert 'C:/Users/me/Desktop/test.pptx', 'pdf', (err, result)->
console.log err
I get
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)
Any idea on if this can be fixed?
me too
I managed to get this library working on Windows... Its not great but ill share my solution. I assume you have already downloaded unoconv from https://github.com/dagwieers/unoconv and installed it somewhere that tickles your fancy. Add the folder you have installed unoconv to your PATH in system environment variables.
OK so pretty standard so far.
Next we mix things up a little bit:
go to the unoconv folder and change the filename "unoconv" to "unoconv.py" (Windows doesnt like files without file types) now a pretty good test from this point to make sure everything is working as it should is to start cmd type: "unoconv.py -h"
You should now see the help file for the unoconv application.
Now the messy bit:
In Windows, the childProcess.spawn function (in Node) doesn't like anything but exe files. This is painful for us Windows users. Some users have suggested using the childProcess.exec function but this has a return size limit of 200kB and is typically only used for scripts/programs that do not return data so I have come up with a band aid for the .spawn.
as spawn only wants to run exe files lets give it one to run! See attached code to run the unoconv application via the cmd command.
unoconv.convert = function(file, outputFormat, options, callback) {
var self = this,
args,
bin = 'cmd',
child,
stdout = [],
stderr = [];
if (_.isFunction(options)) {
callback = options;
options = null;
}
args = ['/s', '/c', 'unoconv.py',
'-f' +outputFormat,
'--stdout'
];
if (options && options.port) {
args.push('-p' + options.port)
}
args.push(file);
if (options && options.bin) {
bin = options.bin;
}
child = childProcess.spawn(bin, args, {windowsVerbatimArguments: true });
child.stdout.on('data', function (data) {
stdout.push(data);
});
child.stderr.on('data', function (data) {
stderr.push(data);
});
child.on('exit', function () {
if (stderr.length) {
return callback(new Error(Buffer.concat(stderr).toString()));
}
callback(null, Buffer.concat(stdout));
});
};