Nodejs always cann't capture child process's stdout data completely, unless child process fllush(stdout)

前端 未结 1 1419
Happy的楠姐
Happy的楠姐 2021-01-22 22:40

I use nodejs to captured its child process\'s stdout data, but always captured the former part of child process\'s stdout data. When I add fllush(stdout),It wor

相关标签:
1条回答
  • 2021-01-22 22:52

    By default, stdout in general is buffered until a newline is written. However, if stdout is not a tty (which is the case here with child_process.spawn()), all output is buffered, regardless of newlines.

    If you don't want to use fflush() manually, you can disable stdout buffering entirely by doing setbuf(stdout, NULL); once at the beginning of your C program.

    0 讨论(0)
提交回复
热议问题