Skip to content

Instantly share code, notes, and snippets.

@niallo
Created October 10, 2012 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niallo/3863486 to your computer and use it in GitHub Desktop.
Save niallo/3863486 to your computer and use it in GitHub Desktop.
node 0.8.11 stdout/stderr setEncoding('utf8') strangeness
var assert = require('assert')
var spawn = require('child_process').spawn
function runTest(cb) {
var proc = spawn("/usr/bin/env", [], {env:{foo:"bar"}})
proc.stdoutBuf = ""
proc.stderrBuf = ""
proc.stdmergedBuf = ""
proc.stdout.on('data', function(buf) {
proc.stdoutBuf += buf
proc.stdmergedBuf += buf
})
proc.stderr.on('data', function(buf) {
proc.stderrBuf += buf
proc.stdmergedBuf += buf
})
proc.on('exit', function(exitCode) {
assert.notEqual(proc.stdoutBuf.length, 0, "proc.stdoutBuf has length 0!")
if (cb) cb()
})
return proc
}
var proc1 = runTest(function() {
console.log("completed test without utf8-encoding")
var proc2 = runTest()
proc2.stdout.setEncoding('utf8')
proc2.stderr.setEncoding('utf8')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment