سؤال

I'm using gnuplot in a bash child process in node js to plot some data and save the figure. This is my code so far:

var term = require('child_process').spawn('bash');
term.stdin.write('gnuplot -p\n');
term.stdin.write('set key outside\n');
term.stdin.write('set term png\n');
term.stdin.write('set output "plot1.png"\n')
term.stdin.write('plot for [col=2:4] "results" using 1:col with points title columnheader\n');
term.stdin.write('set output "plot2.png"\n')
term.stdin.write('plot for [col=5:7] "results" using 1:col with points title columnheader\n');

Is this the more correct and fastest way of doing this? there's anyway I can make it more compact and simple? Also, when I run this inside my node.js script the the child won't exit when I run the script so the script won't exit. How can solve this?

هل كانت مفيدة؟

المحلول

Solution:

spawn gnuplot directly var term = require('child_process').spawn('gnuplot'); instead of the bash.

remove term.stdin.write('gnuplot -p\n'); (-p flag makes gnuplot windows persistent, but there's no need for this because in this case plots are printed to png images)

add term.stdin.write('exit\n') at the end.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top