I’ve noticed strange behavior when trying to redirect the output form a node.js script in Windows. The smallest reproducible example of this behavior is as follows:
From the Windows console (cmd.exe):
c:\> node -e console.log('hello')
hello
From Powershell:
PS C:\> node -e console.log('hello')
PS C:\>
That is to say, it exits without writing anything to the console.
This is a problem because when I try to redirect the output to a file, nothing is written, eg
node -e console.log(123) > temp.txt
is creating an empty file named temp.txt.
Is there something about how node is writing console.out to stdio?
It seems that the problem is in the parenthesis.
Try this:
As for the redirection, there is imho ne reason why this should not work. You may also try to pipe it to
Out-File temp.txt.