wren-lang / wren-cli

A command line tool for the Wren programming language
MIT License
129 stars 30 forks source link

Stdin.readLine aborts when reading from a file #29

Open busterwood opened 4 years ago

busterwood commented 4 years ago

Using bash to redirect Stdin from a file seems to fail.

Here is the simplest example test1.wren:

import "io" for Stdin, Stdout
var line = Stdin.readLine()
System.print("line: " + line)

When I run interactively it works:

chris@WIN-FE4HG5BFASB:~$ wren/wren test1.wren
fred
line: fred
chris@WIN-FE4HG5BFASB:~$

However, when I redirect stdin to read from a non-empty file it fails:

chris@WIN-FE4HG5BFASB:~$ wren/wren test1.wren < sales.txt
Aborted
chris@WIN-FE4HG5BFASB:~$ head sales.txt
--
-- PostgreSQL database dump
--

-- Dumped from database version 11.5
-- Dumped by pg_dump version 11.5 (Debian 11.5-3.pgdg80+1)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;

Using Ubuntu on WSL 2 on Windows 10.

mhermier commented 4 years ago

Digged into this and there is no solutions for this for now. Redirections like these results in UV_FILE type. Current implementation tried to mitigate the issue by making it behave like UV_PIPE, but uv_pipe_init check and fails on UV_FILE. And the deep reason this fails is because of epoll not supporting plain files descriptor.

joshgoebel commented 3 years ago

Redirections like these

Like which? Are there other redirections that do work?


I'm on Mac OS and both 0.3.0 and latest main work just fine for me when piping or redirecting a file (using provided examples). Is this a Windows or platform specific issue? Or perhaps the UV version has been bumped since this was opened and the behavior I'm seeing is new?

joshgoebel commented 3 years ago

@busterwood Could you confirm if this is still an issue with the latest code in main and let us know which platform you're seeing the issue on?