原諒這個愚蠢的問題,如果是這樣,我對Node來說比較新。子進程輸出到socket.io
我在我的節點服務器上產生一個子進程,用於將數據集導入數據庫。子進程使用參數執行osm2pgsl
,它有自己的內部輸出,用於顯示當前處理的數據和已處理內容的計數。
我有一個簡單的節點腳本來產生這個過程,並記錄來自這個過程的信息,當它到達時。我需要訪問的主要信息不通過stdout, stderr or on
進行輪詢,這是有問題的。
節點腳本
var util = require('util'),
spawn = require('child_process').spawn,
file = process.argv[2],
ls = spawn('osm2pgsql', ['--slim', '-d', 'gis', '-U', 'postgres', '--number-processes', '3', file]);
ls.stdout.on('data', function (data) {
process.stdout.write('Currently processing: ' + data.toString() + '\r');
});
ls.stderr.on('data', function (data) {
console.log('stderr: ' + data.toString());
});
ls.on('exit', function (code) {
console.log('child process exited with code ' + code.toString());
});
輸出
Mid: pgsql, scale=100 cache=800
Setting up table: planet_osm_nodes
stderr: NOTICE: table "planet_osm_nodes" does not exist, skipping
stderr: Setting up table: planet_osm_ways
stderr: NOTICE: table "planet_osm_ways" does not exist, skipping
stderr: Setting up table: planet_osm_rels
stderr: NOTICE: table "planet_osm_rels" does not exist, skipping
stderr:
Reading in file: /OSMDATA/great-britain-latest.osm.pbf
Processing: Node(10k 10.0k/s) Way(0k 0.00k/s) Relation(0 0.00/s)
Processing: Node(20k 20.0k/s) Way(0k 0.00k/s) Relation(0 0.00/s)
Processing: Node(30k 30.0k/s) Way(0k 0.00k/s) Relation(0 0.00/s)
從stderr:
線,你可以看到,我能夠訪問流,但Processing: ...
正是我需要的獲得高於一切。這是從子進程內打印的,我不確定如何直接訪問它。
是否有任何方式從我的Nodejs服務器訪問輸出(上圖)?
編輯:我打算把這個輸出管道連接到Socket.io,但我需要首先訪問它,因此標題。