Created
October 10, 2012 06:27
-
-
Save niallo/3863486 to your computer and use it in GitHub Desktop.
node 0.8.11 stdout/stderr setEncoding('utf8') strangeness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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