Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


how to detect if a node js script is running through a shell pipe


how to detect if a node js script is running through a shell pipe  using -'bash,node.js,pipe'

My question is similar to this one: How to detect if my shell script is running through a pipe?. The difference is that the shell script I’m working on is written in Node.js.

Let’s say I enter:

echo "foo bar" | ./test.js


Then how can I get the value "foo bar" in test.js?

I’ve read Unix and Node: Pipes and Streams but that only seems to offer an asynchronous solution (unless I’m mistaken). I’m looking for a synchronous solution. Also, with this technique, it doesn’t seem very straightforward to detect if the script is being piped or not.

TL;DR My question is two-fold:


How to detect if a Node.js script is running through a shell pipe, e.g. echo "foo bar" | ./test.js?
If so, how to read out the piped value in Node.js?

    

asked Sep 18, 2015 by mca.agarwal
0 votes
32 views



Related Hot Questions



Walkin Jobs Opening



Government Jobs Opening


...