wren-cli icon indicating copy to clipboard operation
wren-cli copied to clipboard

Stdin.readLine aborts when reading from a file

Open busterwood opened this issue 5 years ago • 3 comments
trafficstars

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.

busterwood avatar Jan 03 '20 17:01 busterwood

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.

mhermier avatar Jan 03 '20 19:01 mhermier

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 avatar Apr 30 '21 11:04 joshgoebel

@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?

joshgoebel avatar May 14 '21 22:05 joshgoebel