How to ensure node.js child_process.spawn will write error messages to the
console
I'm having a lot of trouble running child processes and getting their
output written to the console. In this episode, I'm trying to use spawn to
run a windows mklink command. The error is the that I don't have
permission to write the file.
My problem, though, is that the error isn't told to me in any way.
The following prints You do not have sufficient privilege to perform this
operation. to the console:
mklink /D C:\some\path\to\my\intended\link C:\path\to\my\folder
But running this in node.js only gives me Error: spawn ENOENT - which is a
highly useless error message:
require('child_process').spawn('mklink',
['/D', 'C:\\some\\path\\to\\my\\intended\\link',
'C:\\path\\to\\my\\folder'],
{stdio:'inherit'})
I get nothing on the console, despite the stdio:'inherit'. I've also tried
the following:
var x = require('child_process').spawn('mklink',
['/D', 'C:\\some\\path\\to\\my\\intended\\link',
'C:\\path\\to\\my\\folder'])
x.stdout.pipe(process.stdout)
x.stderr.pipe(process.stderr)
But no dice. No console output at all. Note that I do get console output
with exec:
var x = require('child_process')
.exec('mklink /D C:\\some\\path\\to\\my\\intended\\link
C:\\path\\to\\my\\folder')
x.stdout.pipe(process.stdout)
x.stderr.pipe(process.stderr)
This shouldn't need any special knowledge of how windows mklink works - my
problem is simply with error reporting with node.js spawn.
What am I doing wrong here?
No comments:
Post a Comment