child_process
モジュール経由でコマンドを実行しようとしましたが、次のようにクライアントブラウザに結果を返します。console.log(stdout)
が見つかりましたが、response.write()
は機能しません。上記のコードchild_process execがクライアントのブラウザに応答できません
function start(response) {
dir_list(function(stdout) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write(stdout);
console.log(stdout);
response.end();
});
function dir_list(callback) {
var exec = require('child_process').exec
child = exec('ls -la', function(error, stdout, stderr) {
callback(stdout);
});
}
私は Node.js: Object value as stdout of child_process.execを参照している私がrefractored、しかし、それは私のために動作しませんunlucklyれます。
ところで、私の元々のコードは次のとおりです。
function start(response) {
console.log("Request handler 'start' was called.");
var exec = require('child_process').exec;
exec("ls -lah", function (error, stdout, stderr) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write(stdout);
console.log(stdout);
response.end();
});
どういう意味ですか?応答はクライアント側で受信されていますか?エラーメッセージはありますか? – supertopi
元のコードは機能しましたか? – Eloff
@superopiそれは私のブラウザで何も得られないことを意味しません。それは有線だ "console.log(stdout);"つまり、コンソールでログ情報を取得できます。 – Weibo