Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Reusing the same file descriptor for child_process.spawn #6192

Closed
wavded opened this issue Sep 7, 2013 · 2 comments
Closed

Reusing the same file descriptor for child_process.spawn #6192

wavded opened this issue Sep 7, 2013 · 2 comments

Comments

@wavded
Copy link

wavded commented Sep 7, 2013

@indutny we talked briefly about this on IRC. To recap, I was interested in knowing if it was by design or perhaps a bug in that you can't reuse the same FD when setting up a stdio config. And if not a bug, curious as to why that is.

Say I have a basic executable that outputs one log to stdout and one to stderr:

#!/usr/bin/env node
console.log('hello')
console.error('world')

If I use spawn with separate FDs, the contents of out.log will contain both hello and world:

var fs = require('fs')
var cp = require('child_process')

fs.unlinkSync('./out.log')
var outFd = fs.openSync('./out.log', 'a')
var errFd = fs.openSync('./out.log', 'a')

cp.spawn('./child', [], { stdio: [ 'ignore', outFd, errFd ] })

However if I share the same FD, only the contents of stdout will get written to out.log:

var fs = require('fs')
var cp = require('child_process')

fs.unlinkSync('./out.log')
var sharedFd = fs.openSync('./out.log', 'a')

cp.spawn('./child', [], { stdio: [ 'ignore', sharedFd, sharedFd ] })

BTW, I am testing on OSX.

@tjfontaine
Copy link

closing as a duplicate of #5831

@bnoordhuis
Copy link
Member

FWIW, it's a bug in libuv. See joyent/libuv#923.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants