2017-10-10 12 views
2

Linux上でstdout経由で出力するバイナリファイルを実行しようとしています。ターミナルから実行すると、美しいストリームのデータが出力されます(50msごとに1行に近い)が、nodeJSスクリプトからchild_process.spawnを実行すると、5秒ごとにデータがチャンクに到達します。child_process.spawn stdoutがチャンクになる

コードスニペット:

const spawn = require('child_process').spawn; 


    // Run all node binaries 
for (let i = 0; i < config.dependencies.length; i++) { 

    // Get details on this binary 
    var repo = config.dependencies[i].name; 
    var version = config.dependencies[i].version; 
    console.log("Running: " + repo + ' version ' + version); 


    // Run this binary 
    node_process[i] = spawn('./'+repo+'/'+repo,[], {stdio: ['pipe', 'pipe', 'pipe']}) 

    node_process[i].stdout.on('data', function(data) { 

    stdout_data=config.dependencies[i].name+ ":"+data.toString(); 
    console.log("Stdout: " + stdout_data) 

}); 
} 

私は標準出力、リアルタイムのデータを印刷するためにすべてのセットアップを持っていると思う、と私は予想通り、これは動作しない理由としては非常に混乱しています。みんなありがとう!

答えて

0

わかった!

spawn('stdbuf', ['-i0', '-o0', '-e0', FilePath]) 

stdbufを使用して、バッファなしでそれを生成します。

関連する問題