node.js spawnSync last line of stdin not taken

Run this in the shell.

node -e "console.log(require('child_process').spawnSync('column', ['-t','-s',','], {input: 'a,b\nc,d', encoding:'utf8'}).stdout)"

I see different behavior on different environments.

  • 6.5.0: prints one line (just a b\n)
  • 4.2.6: prints two lines (a b\nc d\n)

I do see that on the environments exhibiting unexpected behavior where the last line is dropped, appending a newline to the provided input to spawnSync will address the problem. As such, in the future when doing things like this I will be ensuring the input terminates with a newline to stay on the safe side.

However, I am not so sure if I'm being opinionated by expecting node to not simply lose my last line of output if I havent added a newline to flush the stream (which is what I am expecting this issue to be rooted in). So this seems like a bug.

I tried running the different versions of node provided on runkit.com, but they ALL somehow return the unexpected one line output (except for 0.10.x, which is missing the spawnSync API altogether). Now I'm scratching my head.