response.write()在exec中不起作用

时间:2013-07-10 18:29:26

标签: node.js

我正在关注node.js教程并制作一个显示目录内容的简单服务器。

function start(response) {
  console.log("Request handler 'start' was called.");

  // if I put response.write("blah") here it works
  console.log(response);
  exec("ls -lah", function (error, stdout, stderr) {
    console.log(response);
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.write(stdout);
    response.write("asdfasdf");

    console.log("asdf");
    console.log(stdout);
    response.end();
  });
}

这不会在浏览器上打印任何内容,但会显示在控制台上。

我尝试在exec回调函数之外放置response.write(),它在浏览器上完美显示。

Firefox报告说根本没有设置请求,甚至没有设置内容类型标头。如果我在exec回调函数之外移动它,它就会被设置。

0 个答案:

没有答案
相关问题