I think you want to look at dup() and dup2. I see some mumble foo that
this was added to node.js back in 2010 (first patch offered that I saw).
My expectation is you would use it the same as in "C". This link may be of
value:
http://stackoverflow.com/questions/11635219/dup2-dup-why-would-i-need-to-duplicate-a-file-descriptor
The notation "2>&1" instructs the shell to do the dup sequence of system
calls
to make sure the standard file descriptors stdin, stdout, stderr and their
descriptor
numbers all match expectations. The fork() exec() file descriptor tangle
is well documented
in older Unix documents. Many modern systems assume programmers know all
this old stuff and leave it as an exercise for the student. There is
open source
simple shell like code that gets it correct...
Anytime you have multiple writers to the same file there is a risk of
confused output.
Often things are fine up to the point that system load changes and true
concurrency
or time slice conflict happens. Writes to stdout, stderr are not
interlocked on many
systems.
The order can prove important:
i.e. difference between ">/dev/null 2>&1" and "2>&1 >/dev/null"
http://stackoverflow.com/questions/916900/having-trouble-with-fork-pipe-dup2-and-exec-in-c
On Saturday, October 26, 2013 6:19:50 PM UTC-7, Tim Cuthbertson wrote:
> I want to spawn a child process and have *all* output go to the same file.
>
> I tried this:
>
> var fs = require('fs'), childProcess = require('child_process');
> var output = fs.openSync('/tmp/output.log', 'w');
> childProcess.spawn('bash', ['-c', 'echo STOUT; echo STDERR >&2; echo
> DONE;'], {stdio: ['ignore', output, output]});
>
> ...snip ......
>
Is there anything similar in nodejs, or am I stuck with explicitly
> truncating the file, followed by opening two append-mode descriptors?
>
> Cheers,
> - Tim.
>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.