Hacker News new | ask | show | jobs
by z3t4 3845 days ago
I would love to write my bash scripts in node, but end up writing them in bash anyway ... How do you do something like this in node?

  sudo -u 2>&1 >> logfile | tee | echo
1 comments

I'm assuming this isn't a real example of a thing you would want to do, because it doesn't make sense. (redirecting stderr to stdout, stdout to a file, then pipe to tee and echo?)

At any rate, you'd:

1. use some sort of popen()

2. use pipes and pass the same pipe to stdout as stderr

3. pass stdout of one popen to another's stdin

4. just use bash, because this gets so hairy and bash does it really well. When I want to use a complex pipeline of programs in non-bash programs, I'll frequently popen() to a bash script. This is ugly, but if you're really careful (shellshock?) it can be ok.