2

Simple example:

 node  someCode.js|grep "someString"  

Displays someString as it is written out.

Now

  node someCode.js|grep "someString"  > /tmp/someFile &

In another window:

ls -l /tmp/someFile 

shows 0 bytes... so I cannot cat it to see its content. I know that process.stdout.write is a stream that is flushed immediately upon write...

What do I need to do to get the output file updated with content as it is written out? There are complicated ways like writing to UNIX sockets and creating a custom UNIX-socket based cat-like program but thats too heavy for this simple requirement.

asinix
  • 966
  • 1
  • 9
  • 22

1 Answers1

0

I realized that this is more of a Linux than a Node.js question. The answer is here. Its not the accepted answer but one with the maximum votes. So my command looks like:

    node someCode.js|stdbuf -oL grep "someString"  > /tmp/someFile &

One can monitor the progress now in /tmp/someFile as lines are written out. With the L option strings are written as Line-buffered. I will try to edit the question to add Linux as another tag.

asinix
  • 966
  • 1
  • 9
  • 22