RockstarLang / rockstar

Home of the Rockstar programming language
https://codewithrockstar.com/
GNU Affero General Public License v3.0
6.88k stars 223 forks source link

How to read stdin from file or pipe input to rockstar program on command line in Satriani? #297

Closed hugobuddel closed 8 months ago

hugobuddel commented 2 years ago

How can stdin be read from file or pipe in Satriani?

I have these two files:

$ cat parrot.rocks 
Listen to Parrot
Whisper zir

$ cat hello.txt 
hello

Now I want the parrot to say hello, but neither these work:

$ node rockstar parrot.rocks < hello.txt 
$ cat hello.txt | node rockstar parrot.rocks

Both those commands still ask for input, and while I can manually paste the contents of hello.txt into the terminal, the goal is to automate that.

I'm currently developing on rocky, where both these constructs work. However, I'm trying to resolve some inconsistencies between Satriani and rocky, and copy pasting the code into the online editor is now the bottleneck, so I'm hoping to get the command-line working.

Maybe this is standard node behavior? This is the first time for me running node command line programs. Is there some flag I need to specify?

hugobuddel commented 2 years ago

I'm currently developing on GUIX (a GNU Linux distribution), which is a bit unusual distribution, so it could be a problem on my end. Should those commands above work?

Seems that there can be similar problems on windows: https://stackoverflow.com/questions/45890339/stdout-is-not-a-tty-using-bash-for-node-tape-tap-spec (but the suggestions there did not seem to result in anything to resolve my problem).

dylanbeattie commented 2 years ago

No, it's not a GUIX thing, it's to do with how nodeJS handles synchronous IO. Verified as a bug, although fixing it might be entertaining (yay nodeJS)... let me take a look, see if we can wrap the readlineSync stuff in a regular readline so if there's stuff already available on stdin it won't block.

dylanbeattie commented 8 months ago

Rockstar 2.0 will not be built on nodeJS so won't have these kinds of headaches with async IO.