I am having an issue with my Node.js script in the Cloud9 online IDE. I am using the child_process module to run a python script, pass an input with stdin, and receive an output with stdout. I keep receiving an error. Here is the part of my code in question
Node.js
try {
var spawn = require ("child_process").spawn;
var pyProcess = spawn ("python2", ["pythonScript.py"]);
pyProcess.stdin.write ("Test");
pyProcess.stdout.on ("data", function (data) {
console.log (data);
});
} catch (e) {
console.log (e);
}
Python
import sys
sys.stdout.write (sys.stdin.read())
sys.stdout.flush()
Error
<Buffer 68 65 6c 6c 6f>
events.js:141
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at exports._errnoException (util.js:907:11)
at Pipe.onread (net.js:557:26)
When I remove the line
pyProcess.stdin.write ("Test");
the error goes away. Any and all help would be appreciated.
Related
I'm using the IBM Watson IoT NodeJS client to connect and use IBM Watson IoT.
This works when my object with credentials etc. is correct:
var client = new ibm_watson_iot.IotfGateway(MY-JSON-OBJECT-WITH-CREDENTIALS);
But if credentials is wrong, then I get:
events.js:160
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND 1234xyz.messaging.internetofthings.ibmcloud.com 1234xyz.messaging.internetofthings.ibmcloud.com:8883
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
error: Forever detected script exited with code: 1
How do I correctly catch this error in a nice way?
You can always use try/catch block to handler error like that
try{
var client = new ibm_watson_iot.IotfGateway(MY-JSON-OBJECT-WITH-CREDENTIALS);
}
catch(error) {
console.log("Error in connection.. Probably configuration object")
}
I'm trying to use videoshow to convert multiple images to video, I have tried to change my code multiple times but now as you can see this is basically the same as in the module's description page. Still I am receiving the following error as stated below.
videoshow(images)
.save('video.mp4')
.on('start', function (command) {
console.log('ffmpeg process started:', command)
})
.on('error', function (err) {
console.error('Error:', err)
})
.on('end', function (output) {
console.log('Video created in:', output)
})
Error: Error: ffmpeg exited with code 1: Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #2:0
Conversion failed!
at ChildProcess.<anonymous> (C:\Users\xxxxxx\Documents\Visual Studio 2017\Projects\Frame\Frame\server-side\node_modules\fluent-ffmpeg\lib\processor.js:182:22)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
Check aspect ratio and resolution of images, if your all images or any one have different resolution and aspect ratio then it will give you error. try with all same resolution images.
The following is my code, It works in windows with out error but when I setup my project in server (linux) it is not working and throws error
var spawn = require('child_process').spawn,
javaCmd= spawn('java', ['-cp',__dirname+'/Java/jdk1.7.0_45/lib/dom4j.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/geronimo-stax-api_1.0_spec-1.0.1.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/gson-2.2.4.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/mysql-connector-java-5.1.6.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/ooxml-schemas-1.0.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/poi-3.9-20121203.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/poi-ooxml-3.9.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/xmlbeans-2.5.0.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/xmlbeans-xmlpublic-2.6.0.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/excelreader.jar', 'astral.excelreader.Main', catid, id,target_path]);
javaCmd.stdout.on('data', function (data) {
console.log(data);
});
javaCmd.stdout.on('close', function(code) {
console.log(code);
});
javaCmd.stderr.on('data', function (data) {
console.log(data);
});
Following is the error
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)
Anybody know its reason? I did n't set any other path for java. I tried to set using $ vi ~/.bash_profile but I got the following response
-bash: $: command not found
Anybody know how to set path in linux server
I've been working through the learnyoujs and stream-adventure tutorials:
https://github.com/substack/stream-adventure
https://github.com/rvagg/learnyounode#learn-you-the-nodejs-for-much-win
I've gotten all the way through the first set and most of the way thorough the second, but I keep getting an odd error... usually I can get it to go away.
Here's the command/error:
DEV/javascript/streamAdventure ยป stream-adventure run httpserver.js
stream.js:94
throw er; // Unhandled stream error in pipe.
^
Error: connect ECONNREFUSED
at errnoException (net.js:901:11)
at Object.afterConnect [as oncomplete] (net.js:892:19)
This will launch but not kill the process for node, so I ps aux | grep node and then find the process and kill it.
Here's the "working" code from the tutorial:
var http = require('http');
var through = require('through');
var server = http.createServer(function (req, res) {
if (req.method === 'POST') {
req.pipe(through(function (buf) {
this.queue(buf.toString().toUpperCase());
})).pipe(res);
}
else res.end('send me a POST\n');
});
server.listen(8000);
If I just run nod httpserver.js and then curl at it, it works fine.... so does anyone have any insight into what is causing this error?
There is a pull request to fix this, here:
https://github.com/substack/stream-adventure/pull/16
Try to listen on port 8001 instead and rerun verify after closing all processes listening on 8000.
I had the same error, problem wasn't with though node however, it was with mysql.
Ran "mysqld_safe restart" (depends on your version), then it worked fine.
var server = require('http').createServer(function(req, res){
});
server.listen(8080);
This simple example return error in console:
node node_server.js
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: listen EPERM
at errnoException (net.js:670:11)
at Array.0 (net.js:756:28)
at EventEmitter._tickCallback (node.js:192:41)
What is going on?
Port was locked. Topic shutdown.