I'm using node.js and express to create a controller of sorts for my home media centre that can be operated through a browser.
I'm having a lot of trouble spawning the VLC process, but strangely only it works when executed from the node prompt, just not when run from file.
Here is what I have tested:
In the node command line/interpreter: require('child_process').spawn('vlc');
This works as I would expect, I can see the vlc window opens and persists on screen.
If I take the exact same line of code and I place it in another file (say test.js) and run that from the command line with node test.js
nothing happens. Logging out the child process object a few seconds later gives me this:
{ _closesNeeded: 3,
_closesGot: 3,
signalCode: null,
exitCode: 1,
killed: false,
_internal: null,
pid: 11837,
stdin:
{ _handle: null,
_pendingWriteReqs: 0,
_flags: 0,
_connectQueueSize: 0,
destroyed: true,
bytesRead: 0,
bytesWritten: 0,
allowHalfOpen: undefined,
writable: false,
readable: false,
_connecting: false,
_connectQueue: null,
_idleNext: null,
_idlePrev: null },
stdout:
{ _handle: null,
_pendingWriteReqs: 0,
_flags: 1,
_connectQueueSize: 0,
destroyed: true,
bytesRead: 0,
bytesWritten: 0,
allowHalfOpen: undefined,
writable: false,
readable: false,
_events: { close: [Function] },
_connecting: false,
_connectQueue: null,
_idleNext: null,
_idlePrev: null },
stderr:
{ _handle: null,
_pendingWriteReqs: 0,
_flags: 1,
_connectQueueSize: 0,
destroyed: true,
bytesRead: 215,
bytesWritten: 0,
allowHalfOpen: undefined,
writable: false,
readable: false,
_events: { close: [Function] },
_connecting: false,
_connectQueue: null,
_idleNext: null,
_idlePrev: null } }
What is particularly weird about this is that I can launch other programs in the same way and it works. For instance replacing 'vlc' with 'gedit' results in the text editor appearing exactly as expected.
Anyone got ideas as to what this could be?
This is just a hunch, but I bet you are prematurely exiting your test before the VLC process even gets "running" so to speak.
Execute it like this:
var spawn = require('child_process').spawn;
var vlc = spawn('vlc');
vlc.on('exit', function(code){
console.log('Exit code: ' + code);
//EXIT TEST HERE
});
Edit: Just saw 'test.js' and thought you were running a test. Post the relevant part of your Express code.