23785623985
23785623985

Reputation: 91

Node.js spawn() call not working on Windows

I need to print a file using the command line. When doing something like

rundll32 C:\WINDOWS\system32\shimgvw.dll,ImageView_PrintTo "d:\Temp\test.jpg" "Canon_CP1000"

in CMD manually it works just fine and the image gets printed. However, as soon as I use Nodes "spawn" command to achieve the same behaviour it doesn't do anything.

var spawn = require('child_process').spawn;
var cliCmd = spawn('rundll32', [
    'C:\\WINDOWS\\system32\\shimgvw.dll,ImageView_PrintTo "d:\\Temp\\test.jpg" "Canon_CP1000"',
]);
cliCmd.stdout.on('data', function (data) {
    console.log('stdout', data);
});
cliCmd.stderr.on('data', function (data) {
    console.log('stderr', data);
});

There is also no output in the console at all. Other commands in spawn work (e.g. "ipconfig, ['/all']"). I have also tried to separate the space-separated attributes and placing it in an array slot each. No effect.

Help is very much appreciated. Thanks!

Upvotes: 2

Views: 1082

Answers (1)

Brad
Brad

Reputation: 163282

Use an array of parameters to pass to span your child process.

var cliCmd = spawn('rundll32.exe', [
    'C:\\WINDOWS\\system32\\shimgvw.dll,ImageView_PrintTo',  'd:\\Temp\\test.jpg', 'Canon_CP1000'
]);

Also, make sure you have the full name of rundll32.exe. You might also have to specify its path.

Upvotes: 2

Related Questions